/******************************************************************************
 * * setting_security.c - implementation of security setting functions
 *
 * *(C) Copyright 2019 Asr International Ltd.
 * * All Rights Reserved
 * ******************************************************************************/

#include "setting_global.h"

Setting_Security_Setting_Mng_t g_SettingSecuritySettingMng;
VOID                           *gp_SettingSecuritySettingsCurUIDesc = NULL;     // Current Setting_Security_Settings UI description
VOID                           *gp_SettingSecuritySettingCurUIDesc  = NULL;     // Current UI description
VOID                           *gp_SettingChangeAccCodeCurUIDesc    = NULL;     // Current Setting_Change_Access_Code UI description
UINT8                          g_SettingSecurityPinCodeTaRestCharacters;

ACTIVITY_ID                    g_SettingSecurityCheckCallerActId;               // Security check(PIN/PUK) Caller activity ID
ACTIVITY_ID                    g_SettingSecurityAutoNextActIdAfterDone;         // next Activity ID after checking ok & shown done

extern const INT8              g_SettingAcceptedCharsForNumberInput[11];        // used for setting valid pin code chars

// To specify if it's a POWER_ON pin request or hereafter pin request
SETTING_PIN_REQ_STATUS g_SettingSecurityPinReqStatus[2] =
{
    SETTING_PIN_REQUEST_POWERON,SETTING_PIN_REQUEST_POWERON
};

// for external module security/pin check response
Setting_Check_PIN_Cnf_t      gp_SettingSecurityChkPinCnf      = NULL;
Setting_Check_Security_Cnf_t gp_SettingSecurityChkSecurityCnf = NULL;

/**
 * sub-module entry
 * param (in) void
 * return  void
 */
VOID Setting_Security_Main(VOID)
{
    // init manage variable
}

/**
 * sub-module event handler
 * param (in) void
 * return  void
 */
VOID Setting_Security_Event_handle(VOID)
{
    // event and message dispatch
}

/**
 * Set operating action
 * param (in) OperatingAction: SETTING_SECURITY_OPERATION_ACTION_TYPE
 * return void:
 */
VOID Setting_Set_Operating_Action(SETTING_SECURITY_OPERATION_ACTION_TYPE OperatingAction)
{
    // change global variable
    g_SettingSecuritySettingMng.OperatingAction = OperatingAction;
}

/**
 * Set type for pin operating
 * param (in) PinOperatingType: SETTING_PIN_OPERATION_TYPE
 * return void:
 */
VOID Setting_Set_Pin_Operating_Type(SETTING_PIN_OPERATION_TYPE PinOperatingType)
{
    // change global variable
    g_SettingSecuritySettingMng.PinOperatingType = PinOperatingType;
}

/**
 * initiate security sub-module
 * param (in) pNvPara: NV_UI_Settings_t
 * return  void
 */
VOID Setting_Security_Init_Req(NV_UI_Settings_t *pNvPara)
{
    Hal_Mem_Set(&g_SettingSecuritySettingMng, 0, sizeof(Setting_Security_Setting_Mng_t));

    // init manage variable
    g_SettingSecuritySettingMng.IsSecurityOn = pNvPara->SecuritySetting.SecurityStatus;
    Hal_Mem_Copy(g_SettingSecuritySettingMng.SecurityCode, pNvPara->SecuritySetting.SecurityCode,NV_SETTING_SECURITY_CODE_LEN);

    Setting_Set_Operating_Action(SETTING_SECURITY_ACTION_NONE);
} /* Setting_Security_Init_Req */

/**
 * Set operating sim ID
 * param (in) OperatingSimId: MMI_MODEM_SIM_ID
 * return void:
 */
VOID Setting_Set_Operating_Sim_Id(MMI_MODEM_SIM_ID OperatingSimId)
{
    // change global variable
    g_SettingSecuritySettingMng.OperatingSIM = OperatingSimId;
}

/**
 * Set PIN request status
 * param (in) PinReqStatus: SETTING_PIN_REQUEST_STATUS
 *       (in) SimId:  MMI_MODEM_SIM_ID
 *       (in) PIN: INT*
 * return  UINT8 Retry Left: MMI_MODEM_PIN_CHECK_OK when check OK
 */
UINT8 Setting_Set_Pin_Request_Status(BOOL PinReqStatus, MMI_MODEM_SIM_ID SimId, const INT8 *PIN)
{
    INT8                 *PinCode;
    MMI_Modem_Pin_Lock_t PinLockSet;

    PinCode = Hal_Mem_Alloc(10);
    Hal_Mem_Set(PinCode, 0, 10);
    Hal_Mem_Copy(PinCode, PIN, strlen(PIN));

    PinLockSet.SimId     = SimId;
    PinLockSet.PinType   = MMI_MODEM_PIN1;
    PinLockSet.PinEnable = PinReqStatus;
    MMI_Modem_Enable_Pin_Lock(&PinLockSet, PinCode);

    return(PinLockSet.RetriesLeft);
}

/**
 * Set PIN trying flag
 * param (in) IsPinTrying: BOOL
 * return void:
 */
VOID Setting_Set_Pin_Trying(BOOL IsPinTrying)
{
    // change global variable
    g_SettingSecuritySettingMng.IsPinTrying = IsPinTrying;
}

/**
 * Set status for access code changing
 * param (in) AccCodeChgStatus: SETTING_ACC_CODE_CHG_STATUS
 * return void:
 */
VOID Setting_Set_Access_Code_Change_Status(SETTING_ACC_CODE_CHG_STATUS AccCodeChgStatus)
{
    // change global variable
    g_SettingSecuritySettingMng.AccCodeChgStatus = AccCodeChgStatus;
}

/**
 * Set security code request status
 * param (in) SecurityStatus: SETTING_SECURITY_REQUEST_STATUS
 * return void:
 */
VOID Setting_Set_Security_Status(BOOL SecurityStatus)
{
    // change global variable
    g_SettingSecuritySettingMng.IsSecurityOn = SecurityStatus;

    // nv write
    UI_NV_Write_Req(NV_SECTION_UI_SETTINGS, NV_SETTING_SECURITY_STAT_OFFSET,NV_SETTING_SECURITY_STAT_LEN,&SecurityStatus);
}

/**
 * Set security code
 * param (in) SecurityCode: INT8*
 * return void:
 */
VOID Setting_Set_Security_code(INT8 *SecurityCode)
{
    // change global variable--SecurityCode
    Hal_Mem_Copy(g_SettingSecuritySettingMng.SecurityCode, SecurityCode, NV_SETTING_SECURITY_CODE_LEN);

    // nv write
    UI_NV_Write_Req(NV_SECTION_UI_SETTINGS, NV_SETTING_SECURITY_CODE_OFFSET,NV_SETTING_SECURITY_CODE_LEN,(UINT8 *)SecurityCode);
}

/**
 * Verity security code from user
 * param (in) SecurityCode: INT8*
 * return BOOL: verify result, FALSE:not match, TRUE:match
 */
BOOL Setting_Verify_Security_code(INT8 *SecurityCode)
{
    UINT8 i;
    BOOL  Result = TRUE;

    // compare inputted SecurityCode and SecurityCode
    for (i = 0; i < NV_SETTING_SECURITY_CODE_LEN; i++)
    {
        if (SecurityCode[i] != g_SettingSecuritySettingMng.SecurityCode[i])
        {
            Result = FALSE;
            break;
        }
    }

    return(Result);
}

/**
 * Verity new security code from user
 * param (in) SecurityCode: INT8*
 * return BOOL: verify result, FALSE:not match, TRUE:match
 */
BOOL Setting_Verify_New_Security_code(INT8 *SecurityCode)
{
    UINT8 i;
    BOOL  Result = TRUE;

    // compare inputted SecurityCode and SecurityCode
    for (i = 0; i < NV_SETTING_SECURITY_CODE_LEN; i++)
    {
        if (SecurityCode[i] != g_SettingSecuritySettingMng.NewSecurityCode[i])
        {
            Result = FALSE;
            break;
        }
    }

    return(Result);
}

/**
 * Set PIN or PIN2 code from user
 * param (in) PinCode: INT8*
 * return void:
 */
VOID Setting_Set_New_Pin_code(INT8 *PinCode)
{
    // change global variable--NewPinCode
    Hal_Mem_Copy(g_SettingSecuritySettingMng.NewPinCode, PinCode, SETTING_SECURITY_PIN_CODE_LEN);
}

/**
 * Store PUK or PUK2 code from user
 * param (in) PukCode: INT8*
 * return void:
 */
VOID Setting_Store_Puk_code(INT8 *PukCode)
{
    Hal_Mem_Copy(g_SettingSecuritySettingMng.PukCode, PukCode, SETTING_SECURITY_PUK_CODE_LEN);
}

/**
 * Store old PIN or PIN2 code from user
 * param (in) OldPinCode: INT8*
 * return void:
 */
VOID Setting_Store_Old_Pin_code(INT8 *OldPinCode)
{
    Hal_Mem_Copy(g_SettingSecuritySettingMng.OldPinCode, OldPinCode, SETTING_SECURITY_PIN_CODE_LEN);
}

/**
 * Verify PIN code from user inputting
 * param (in) PinCode: INT8*
 * return BOOL: verify result, FALSE:not match, TRUE:match
 */
BOOL Setting_Verify_New_Pin_code(INT8 *PinCode)
{
    UINT8 i;
    BOOL  Result = TRUE;

    // compare inputted PinCode and NewPinCode
    for (i = 0; i < SETTING_SECURITY_PIN_CODE_LEN; i++)
    {
        if (PinCode[i] != g_SettingSecuritySettingMng.NewPinCode[i])
        {
            Result = FALSE;
            break;
        }
    }

    return(Result);
}

/**
 *
 * Callback of Setting_Enter_Security_Code, on create
 * param (in) NormalNoTitleLblTaDesc: UI_Normal_NoTitle_Label_Ta_Desc_t*
 * return void:
 */
VOID Display_Setting_Enter_Security_Code_Create(VOID *pPara)
{
    INT8                              LabelValue[100];
    UINT8                             LabelLen;
    INT8                              Text[50];
    UINT8                             TextLen;
    UINT8                             MaxTaInputLen = SETTING_SECURITY_PIN_CODE_LEN;
    MMI_Modem_Pin_Lock_t              PinLockQuery;
    UI_PHONE_TEXT_ID                  TryLeftTxtId;

    INT8                              RestCharValue[3] = { 0, 0, 0 };

    UI_Normal_NoTitle_Label_Ta_Desc_t *NormalNoTitleLblTaDesc = NULL;

    NormalNoTitleLblTaDesc = (UI_Normal_NoTitle_Label_Ta_Desc_t *)pPara;

    Ime_Set_Mode(LV_IME_MODE_NUM);
    Ime_Set_SingleMode(TRUE);

    // set title label: Enter SIMx PINx/PUKx code. x tries left/1 try left
    Hal_Mem_Set(LabelValue, 0, 100);
    strcpy(LabelValue, lv_lang_get_text(NormalNoTitleLblTaDesc->ContLabel.TxtId));
    LabelLen = strlen(LabelValue);
    if (TRUE == g_SettingSecuritySettingMng.IsPinTrying)
    {
        PinLockQuery.SimId = g_SettingSecuritySettingMng.OperatingSIM;
        // PinLockQuery.PinEnable = ;
        if (  (SETTING_PIN_OPERATION_PIN1 == g_SettingSecuritySettingMng.PinOperatingType)
           || (SETTING_PIN_OLD_ENTERING == g_SettingSecuritySettingMng.AccCodeChgStatus))
        {
            PinLockQuery.PinType = MMI_MODEM_PIN1;
            MaxTaInputLen        = SETTING_SECURITY_PIN_CODE_LEN;
        }
        else if (  (SETTING_PIN_OPERATION_PIN2 == g_SettingSecuritySettingMng.PinOperatingType)
                || (SETTING_PIN2_OLD_ENTERING == g_SettingSecuritySettingMng.AccCodeChgStatus))
        {
            PinLockQuery.PinType = MMI_MODEM_PIN2;
            MaxTaInputLen        = SETTING_SECURITY_PIN_CODE_LEN;
        }
        else if (  (SETTING_PIN_OPERATION_PUK1 == g_SettingSecuritySettingMng.PinOperatingType)
                || (SETTING_PUK_ENTERING == g_SettingSecuritySettingMng.AccCodeChgStatus))
        {
            PinLockQuery.PinType = MMI_MODEM_PUK;
            MaxTaInputLen        = SETTING_SECURITY_PUK_CODE_LEN;
        }
        else if (  (SETTING_PIN_OPERATION_PUK2 == g_SettingSecuritySettingMng.PinOperatingType)
                || (SETTING_PUK2_ENTERING == g_SettingSecuritySettingMng.AccCodeChgStatus))
        {
            PinLockQuery.PinType = MMI_MODEM_PUK2;
            MaxTaInputLen        = SETTING_SECURITY_PUK_CODE_LEN;
        }
        MMI_Modem_Query_Pin_Lock(&PinLockQuery);

        // x tries left/1 try left
        LabelValue[LabelLen++] = '\n';
        if (PinLockQuery.RetriesLeft >= 10)
        {
            LabelValue[LabelLen++] = PinLockQuery.RetriesLeft / 10 + 0x30;
            LabelValue[LabelLen++] = PinLockQuery.RetriesLeft % 10 + 0x30;
            LabelValue[LabelLen++] = ' ';                   // add space
            TryLeftTxtId           = PHONE_TEXT_ID_TRIES_LEFT;
        }
        else if (PinLockQuery.RetriesLeft > 1)
        {
            LabelValue[LabelLen++] = PinLockQuery.RetriesLeft % 10 + 0x30;
            LabelValue[LabelLen++] = ' ';                   // add space
            TryLeftTxtId           = PHONE_TEXT_ID_TRIES_LEFT;
        }
        else
        {
            TryLeftTxtId = PHONE_TEXT_ID_1TRY_LEFT;
        }

        Hal_Mem_Set(Text, 0, 50);
        strcpy(Text, lv_lang_get_text(TryLeftTxtId));
        TextLen = strlen(Text);
        Hal_Mem_Copy(&LabelValue[LabelLen], Text, TextLen);
        LabelLen += TextLen;
    }
    lv_label_set_text(NormalNoTitleLblTaDesc->ContLabel.Label, LabelValue);

    g_SettingSecurityPinCodeTaRestCharacters = MaxTaInputLen;
    RestCharValue[0]                         = g_SettingSecurityPinCodeTaRestCharacters + 0x30;

    lv_label_set_text(NormalNoTitleLblTaDesc->ContLabelTr.Label, RestCharValue);

    // set right button text to "Back"
    lv_label_set_text(lv_obj_get_child(NormalNoTitleLblTaDesc->ButtonCont.ButtonR.Button, NULL),lv_lang_get_text(PHONE_TEXT_ID_BACK));

    // set max length of TA & password mode
    lv_textarea_set_text(NormalNoTitleLblTaDesc->ContTa.TextArea, "");
    lv_textarea_set_max_length(NormalNoTitleLblTaDesc->ContTa.TextArea, MaxTaInputLen);
    lv_textarea_set_pwd_mode(NormalNoTitleLblTaDesc->ContTa.TextArea, TRUE);

    // set valid characters acceptable as input number
    lv_textarea_set_accepted_chars(NormalNoTitleLblTaDesc->ContTa.TextArea,g_SettingAcceptedCharsForNumberInput);

    // in external requested pin/puk checking case, disable the BACK button
    if (  (SETTING_SECURITY_ACTION_EXT_PIN_CHK_NO_CNF ==
           g_SettingSecuritySettingMng.OperatingAction)
       || (SETTING_SECURITY_ACTION_EXT_PIN_CHK_WITH_CNF ==
           g_SettingSecuritySettingMng.OperatingAction))
    {
        lv_obj_set_hidden(NormalNoTitleLblTaDesc->ButtonCont.ButtonR.Button, TRUE);
    }
} /* Display_Setting_Enter_Security_Code_Create */

/**
 *
 * Callback of Setting_Enter_Security_Code, on destroy
 * param (in) NormalNoTitleLblTaDesc: UI_Normal_NoTitle_Label_Ta_Desc_t*
 * return void:
 */
VOID Display_Setting_Enter_Security_Code_Destroy(VOID *NormalNoTitleLblTaDesc)
{
    Hal_Mem_Free(NormalNoTitleLblTaDesc);
}

/**
 * display Display_Setting_Security_Puk_Blocked
 * param (in) CallerActId : ACTIVITY_ID, the activity Id from which entered this screen
 *       (in) TxtId       : UI_PHONE_TEXT_ID, the text shown on screen
 *       (in) NextActId   : ACTIVITY_ID, the next activity Id
 *       (in) TriesLeftEnabled: BOOL, whether to show "x tries left"
 * return void:
 */
VOID Display_Setting_Security_Puk_Blocked(ACTIVITY_ID      CallerActId,
                                          UI_PHONE_TEXT_ID TxtId,
                                          ACTIVITY_ID      NextActId)
{
    if ((PHONE_TEXT_ID_SIM1PUK_BLOCKED == TxtId) || (PHONE_TEXT_ID_SIM2PUK_BLOCKED == TxtId))
    {
        // PUK1 blocked handled as SIM invalid?
        // g_SettingSimStatus[g_SettingSecuritySettingMng.OperatingSIM] = FALSE;

        // it's a puk check request from external module
        if (SETTING_SECURITY_ACTION_EXT_PIN_CHK_NO_CNF ==
            g_SettingSecuritySettingMng.OperatingAction)
        {
            Nav_Forward(CallerActId, NextActId, NULL, NULL);
            Setting_Set_Operating_Action(SETTING_SECURITY_ACTION_NONE);
        }
        else if (SETTING_SECURITY_ACTION_EXT_PIN_CHK_WITH_CNF ==
                 g_SettingSecuritySettingMng.OperatingAction)
        {
            gp_SettingSecurityChkPinCnf(g_SettingSecuritySettingMng.OperatingSIM, SETTING_ERROR);
            // gp_SettingSecurityChkPinCnf = NULL;
            Setting_Set_Operating_Action(SETTING_SECURITY_ACTION_NONE);
        }
        else
        {
            Display_Setting_Error(CallerActId, TxtId, NextActId, TRUE);
        }
    }

    // PUK2 block not affect user normal service,just report error
    else if ((PHONE_TEXT_ID_SIM1PUK2_BLOCKED == TxtId) || (PHONE_TEXT_ID_SIM2PUK2_BLOCKED == TxtId))
    {
        Display_Setting_Error(CallerActId, TxtId, NextActId, TRUE);
    }
}

/**
 *
 * Update screen of Setting_Enter_Security_Code
 * param (in) NormalNoTitleLblTaDesc: UI_Normal_NoTitle_Label_Ta_Desc_t*
 * return void:
 */
VOID Display_Setting_Enter_Security_Code_Update_Screen(UI_Normal_NoTitle_Label_Ta_Desc_t *NormalNoTitleLblTaDesc,
                                                       UINT8                             TryLeftCnt)
{
    INT8             LabelValue[100];
    UINT8            LabelLen;
    INT8             Text[50];
    UINT8            TextLen;
    UINT8            MaxTaInputLen = 4;
    UINT8            i;

    UI_PHONE_TEXT_ID TryLeftTxtId;

    INT8             RestCharValue[3] = { 0, 0, 0 };

    // set title label: Enter SIMx PINx/PUKx code. x tries left/1 try left
    Hal_Mem_Set(LabelValue, 0, 100);
    strcpy(LabelValue, lv_lang_get_text(NormalNoTitleLblTaDesc->ContLabel.TxtId));
    LabelLen = strlen(LabelValue);
    if (TRUE == g_SettingSecuritySettingMng.IsPinTrying)
    {
        if (SETTING_PIN_OPERATION_PIN1 == g_SettingSecuritySettingMng.PinOperatingType)
        {
            MaxTaInputLen = SETTING_SECURITY_PIN_CODE_LEN;
        }
        else if (SETTING_PIN_OPERATION_PIN2 == g_SettingSecuritySettingMng.PinOperatingType)
        {
            MaxTaInputLen = SETTING_SECURITY_PIN_CODE_LEN;
        }
        else if (SETTING_PIN_OPERATION_PUK1 == g_SettingSecuritySettingMng.PinOperatingType)
        {
            MaxTaInputLen = SETTING_SECURITY_PUK_CODE_LEN;
        }
        else if (SETTING_PIN_OPERATION_PUK2 == g_SettingSecuritySettingMng.PinOperatingType)
        {
            MaxTaInputLen = SETTING_SECURITY_PUK_CODE_LEN;
        }
        else if (SETTING_PIN_OPERATION_PUK1_PIN_NEW_ENTERING == g_SettingSecuritySettingMng.PinOperatingType)
        {
            MaxTaInputLen = SETTING_SECURITY_PIN_CODE_LEN;
        }
        else if (SETTING_PIN_OPERATION_PUK1_PIN_NEW_VERIFYING == g_SettingSecuritySettingMng.PinOperatingType)
        {
            MaxTaInputLen = SETTING_SECURITY_PIN_CODE_LEN;
        }

        // x tries left/1 try left
        LabelValue[LabelLen++] = ' ';
        if (TryLeftCnt >= 10)
        {
            LabelValue[LabelLen++] = TryLeftCnt / 10 + 0x30;
            LabelValue[LabelLen++] = TryLeftCnt % 10 + 0x30;
            TryLeftTxtId           = PHONE_TEXT_ID_TRIES_LEFT;
        }
        else if (TryLeftCnt > 1)
        {
            LabelValue[LabelLen++] = TryLeftCnt % 10 + 0x30;
            TryLeftTxtId           = PHONE_TEXT_ID_TRIES_LEFT;
        }
        else
        {
            TryLeftTxtId = PHONE_TEXT_ID_1TRY_LEFT;
        }

        Hal_Mem_Set(Text, 0, 50);
        strcpy(Text, lv_lang_get_text(TryLeftTxtId));
        TextLen = strlen(Text);
        Hal_Mem_Copy(&LabelValue[LabelLen], Text, TextLen);
        LabelLen += TextLen;
    }
    lv_label_set_text(NormalNoTitleLblTaDesc->ContLabel.Label, LabelValue);

    g_SettingSecurityPinCodeTaRestCharacters = MaxTaInputLen;
    RestCharValue[0]                         = g_SettingSecurityPinCodeTaRestCharacters + 0x30;

    lv_label_set_text(NormalNoTitleLblTaDesc->ContLabelTr.Label, RestCharValue);

    // clear the TA
    TextLen = strlen(lv_textarea_get_text(NormalNoTitleLblTaDesc->ContTa.TextArea));
    for (i = 0; i < TextLen; i++)
    {
        lv_textarea_del_char(NormalNoTitleLblTaDesc->ContTa.TextArea);
    }

    // When text area is cleared into empty state, right key: CLEAR -> BACK
    NormalNoTitleLblTaDesc->ButtonCont.ButtonR.TxtId = PHONE_TEXT_ID_BACK;
    lv_label_set_text(lv_obj_get_child(NormalNoTitleLblTaDesc->ButtonCont.ButtonR.Button,NULL),(INT8 *)lv_lang_get_text(NormalNoTitleLblTaDesc->ButtonCont.ButtonR.TxtId));
    lv_textarea_set_max_length(NormalNoTitleLblTaDesc->ContTa.TextArea, MaxTaInputLen);
} /* Display_Setting_Enter_Security_Code_Update_Screen */

/**
 *
 * Handling PIN/PUK try result
 * param (in) TryResult: UINT8, MMI_MODEM_PIN_CHECK_OK or try left count
 * return void:
 */
VOID Display_Setting_Enter_Security_Code_Handle_PinPuk_Try_Result(UINT8 TryResult)
{
    UI_Normal_NoTitle_Label_Ta_Desc_t *NormalNoTitleLblTaDesc;
    MMI_Modem_Pin_Lock_t              PinLockQuery;

    NormalNoTitleLblTaDesc =
        (UI_Normal_NoTitle_Label_Ta_Desc_t *)gp_SettingSecuritySettingCurUIDesc;

    // check ok
    if (MMI_MODEM_PIN_CHECK_OK == TryResult)
    {
        // PIN check ok, entering next screen
        if (  (SETTING_PIN_OPERATION_PIN1 == g_SettingSecuritySettingMng.PinOperatingType)
           || (SETTING_PIN_OPERATION_PIN2 == g_SettingSecuritySettingMng.PinOperatingType))
        {
            if (SETTING_SECURITY_ACTION_EXT_PIN_CHK_NO_CNF ==
                g_SettingSecuritySettingMng.OperatingAction)
            {
                Nav_Forward(ACT_ID_SETTING_ENTER_SECURITY_CODE, g_SettingSecurityCheckCallerActId,NULL, NULL);
                Setting_Set_Operating_Action(SETTING_SECURITY_ACTION_NONE);
                Setting_Set_Pin_Operating_Type(SETTING_PIN_OPERATION_OFF);
            }
            else if (SETTING_SECURITY_ACTION_EXT_PIN_CHK_WITH_CNF ==
                     g_SettingSecuritySettingMng.OperatingAction)
            {
                Setting_Set_Operating_Action(SETTING_SECURITY_ACTION_NONE);
                Setting_Set_Pin_Operating_Type(SETTING_PIN_OPERATION_OFF);
                Nav_Back(ACT_ID_SETTING_ENTER_SECURITY_CODE);
                gp_SettingSecurityChkPinCnf(g_SettingSecuritySettingMng.OperatingSIM, SETTING_OK);
                // gp_SettingSecurityChkPinCnf = NULL;
            }
            else if (SETTING_SECURITY_ACTION_PIN_CODE_REQUEST ==
                     g_SettingSecuritySettingMng.OperatingAction)
            {
                // update PIN request status: OFF->ON, or ON->OFF, then display setting_done
                if (SETTING_PIN_OPERATION_PIN1 == g_SettingSecuritySettingMng.PinOperatingType)
                {
                    if (FALSE ==
                        g_SettingSecuritySettingMng.IsPinRequest[g_SettingSecuritySettingMng.
                                                                     OperatingSIM])
                    {
                        g_SettingSecuritySettingMng.IsPinRequest[g_SettingSecuritySettingMng.
                                                                     OperatingSIM] = TRUE;
                    }
                    else
                    {
                        g_SettingSecuritySettingMng.IsPinRequest[g_SettingSecuritySettingMng.
                                                                     OperatingSIM] = FALSE;
                    }
                    // update to SIM
                    // Setting_Set_Pin_Request_Status(g_SettingSecuritySettingMng.IsPinRequest[g_SettingSecuritySettingMng.OperatingSIM],g_SettingSecuritySettingMng.OperatingSIM);
                    if (MMI_MODEM_SIM_1 == g_SettingSecuritySettingMng.OperatingSIM)
                    {
                        if (TRUE == g_SettingSecuritySettingMng.IsPinRequest[g_SettingSecuritySettingMng.OperatingSIM])
                        {
                            Display_Setting_SIM_Selection_Set(PHONE_TEXT_ID_ON, LV_LANG_TXT_ID_NONE, NULL, NULL);
                        }
                        else
                        {
                            Display_Setting_SIM_Selection_Set(PHONE_TEXT_ID_OFF, LV_LANG_TXT_ID_NONE, NULL, NULL);
                        }
                    }
                    else
                    {
                        if (TRUE == g_SettingSecuritySettingMng.IsPinRequest[g_SettingSecuritySettingMng.OperatingSIM])
                        {
                            Display_Setting_SIM_Selection_Set(LV_LANG_TXT_ID_NONE, PHONE_TEXT_ID_ON, NULL, NULL);
                        }
                        else
                        {
                            Display_Setting_SIM_Selection_Set(LV_LANG_TXT_ID_NONE, PHONE_TEXT_ID_OFF, NULL, NULL);
                        }
                    }

                    Display_Setting_Done(ACT_ID_SETTING_ENTER_SECURITY_CODE, PHONE_TEXT_ID_DONE,ACT_ID_SETTING_SIM_SELECTION);
                }
            }
        }
        else if (SETTING_PIN_OPERATION_PUK1_PIN_NEW_VERIFYING == g_SettingSecuritySettingMng.PinOperatingType)
        {
            Setting_Set_Pin_Operating_Type(SETTING_PIN_OPERATION_OFF);

            // it's a puk check request from external module
            if (SETTING_SECURITY_ACTION_EXT_PIN_CHK_NO_CNF ==
                g_SettingSecuritySettingMng.OperatingAction)
            {
                Setting_Set_Operating_Action(SETTING_SECURITY_ACTION_NONE);
                Nav_Forward(ACT_ID_SETTING_ENTER_SECURITY_CODE, g_SettingSecurityCheckCallerActId,NULL, NULL);
            }
            else if (SETTING_SECURITY_ACTION_EXT_PIN_CHK_WITH_CNF ==
                     g_SettingSecuritySettingMng.OperatingAction)
            {
                Setting_Set_Operating_Action(SETTING_SECURITY_ACTION_NONE);
                Nav_Back(ACT_ID_SETTING_ENTER_SECURITY_CODE);
                gp_SettingSecurityChkPinCnf(g_SettingSecuritySettingMng.OperatingSIM, SETTING_OK);
                // gp_SettingSecurityChkPinCnf = NULL;
            }
            else if (SETTING_SECURITY_ACTION_PIN_CODE_REQUEST ==
                     g_SettingSecuritySettingMng.OperatingAction)
            {
                // update PIN request status: OFF->ON, or ON->OFF, then display setting_done
                // (currently assume no PIN2 checking case except from external module)
                if (FALSE ==
                    g_SettingSecuritySettingMng.IsPinRequest[g_SettingSecuritySettingMng.
                                                                 OperatingSIM])
                {
                    g_SettingSecuritySettingMng.IsPinRequest[g_SettingSecuritySettingMng.
                                                                 OperatingSIM] = TRUE;
                }
                else
                {
                    g_SettingSecuritySettingMng.IsPinRequest[g_SettingSecuritySettingMng.
                                                                 OperatingSIM] = FALSE;
                }
                // update to SIM
                Setting_Set_Pin_Request_Status(g_SettingSecuritySettingMng.IsPinRequest[
                                                   g_SettingSecuritySettingMng.OperatingSIM],g_SettingSecuritySettingMng.OperatingSIM,g_SettingSecuritySettingMng.NewPinCode);
                Hal_Mem_Set(g_SettingSecuritySettingMng.NewPinCode, 0, SETTING_SECURITY_PIN_CODE_LEN);

                if (MMI_MODEM_SIM_1 == g_SettingSecuritySettingMng.OperatingSIM)
                {
                    if (TRUE == g_SettingSecuritySettingMng.IsPinRequest[g_SettingSecuritySettingMng.OperatingSIM])
                    {
                        Display_Setting_SIM_Selection_Set(PHONE_TEXT_ID_ON, LV_LANG_TXT_ID_NONE, NULL, NULL);
                    }
                    else
                    {
                        Display_Setting_SIM_Selection_Set(PHONE_TEXT_ID_OFF, LV_LANG_TXT_ID_NONE, NULL, NULL);
                    }
                }
                else
                {
                    if (TRUE == g_SettingSecuritySettingMng.IsPinRequest[g_SettingSecuritySettingMng.OperatingSIM])
                    {
                        Display_Setting_SIM_Selection_Set(LV_LANG_TXT_ID_NONE, PHONE_TEXT_ID_ON, NULL, NULL);
                    }
                    else
                    {
                        Display_Setting_SIM_Selection_Set(LV_LANG_TXT_ID_NONE, PHONE_TEXT_ID_OFF, NULL, NULL);
                    }
                }

                Display_Setting_Done(ACT_ID_SETTING_ENTER_SECURITY_CODE, PHONE_TEXT_ID_DONE,ACT_ID_SETTING_SIM_SELECTION);
            }
        }

        // 2019-05-24, PUK checking needs new PIN together, begin
        // when PUK check ok
        // else if (  // (PHONE_TEXT_ID_ENTER_SIM1_PUK == NormalNoTitleLblTaDesc->ContLabel.TxtId)
        // || (PHONE_TEXT_ID_ENTER_SIM2_PUK == NormalNoTitleLblTaDesc->ContLabel.TxtId))
        // (PHONE_TEXT_ID_VERIFY_NEW_PIN == NormalNoTitleLblTaDesc->ContLabel.TxtId)
        // &&
        // (SETTING_PIN_NEW_VERIFYING_PUK_CHK == g_SettingSecuritySettingMng.AccCodeChgStatus))
        // 2019-05-24, PUK checking needs new PIN together, end
        else if (SETTING_PIN_NEW_VERIFYING_PUK_CHK == g_SettingSecuritySettingMng.AccCodeChgStatus)
        {
            // if it's a pin check request from pin code request menu, update ON/OFF status before re-enter PIN code
            // i.e. whether re-enter PIN code succeed or not, the pin check has successfully passed
            if (SETTING_SECURITY_ACTION_PIN_CODE_REQUEST ==
                g_SettingSecuritySettingMng.OperatingAction)
            {
                // update PIN request status: OFF->ON, or ON->OFF, then display setting_done
                // (currently assume no PIN2 checking case except from external module)
                if (FALSE ==
                    g_SettingSecuritySettingMng.IsPinRequest[g_SettingSecuritySettingMng.
                                                                 OperatingSIM])
                {
                    g_SettingSecuritySettingMng.IsPinRequest[g_SettingSecuritySettingMng.
                                                                 OperatingSIM] = TRUE;
                }
                else
                {
                    g_SettingSecuritySettingMng.IsPinRequest[g_SettingSecuritySettingMng.
                                                                 OperatingSIM] = FALSE;
                }
                // update to SIM
                Setting_Set_Pin_Request_Status(g_SettingSecuritySettingMng.IsPinRequest[
                                                   g_SettingSecuritySettingMng.OperatingSIM],g_SettingSecuritySettingMng.OperatingSIM,g_SettingSecuritySettingMng.NewPinCode);
                Hal_Mem_Set(g_SettingSecuritySettingMng.NewPinCode, 0, SETTING_SECURITY_PIN_CODE_LEN);
            }

            // 2019-05-24, PUK checking needs new PIN together, begin
            // Setting_Set_Access_Code_Change_Status(SETTING_PIN_NEW_ENTERING);
            // NormalNoTitleLblTaDesc->ContLabel.TxtId = PHONE_TEXT_ID_ENTER_NEW_PIN;
            // Setting_Set_Pin_Trying(FALSE);
            // Display_Setting_Enter_Security_Code_Update_Screen(NormalNoTitleLblTaDesc, 0);

            // it's a puk check request from external module
            if (SETTING_SECURITY_ACTION_EXT_PIN_CHK_NO_CNF ==
                g_SettingSecuritySettingMng.OperatingAction)
            {
                Nav_Forward(ACT_ID_SETTING_ENTER_SECURITY_CODE, g_SettingSecurityCheckCallerActId,NULL, NULL);
                Setting_Set_Operating_Action(SETTING_SECURITY_ACTION_NONE);
            }
            else if (SETTING_SECURITY_ACTION_EXT_PIN_CHK_WITH_CNF ==
                     g_SettingSecuritySettingMng.OperatingAction)
            {
                gp_SettingSecurityChkPinCnf(g_SettingSecuritySettingMng.OperatingSIM, SETTING_OK);
                // gp_SettingSecurityChkPinCnf = NULL;
                Setting_Set_Operating_Action(SETTING_SECURITY_ACTION_NONE);
            }
            else
            {   // set new PIN code successfully,reset PIN procedure
                Setting_Set_Access_Code_Change_Status(SETTING_PIN_OLD_ENTERING);
                Setting_Set_Pin_Trying(TRUE);

                Display_Setting_Done(ACT_ID_SETTING_ENTER_SECURITY_CODE, PHONE_TEXT_ID_DONE,ACT_ID_SETTING_SIM_SELECTION);
            }
            // 2019-05-24, PUK checking needs new PIN together, end
        }
        // 2019-05-24, PUK checking needs new PIN together, begin
        // else if (  // (PHONE_TEXT_ID_ENTER_SIM1_PUK2 == NormalNoTitleLblTaDesc->ContLabel.TxtId)
        // || (PHONE_TEXT_ID_ENTER_SIM2_PUK2 == NormalNoTitleLblTaDesc->ContLabel.TxtId))
        // (PHONE_TEXT_ID_VERIFY_NEW_PIN == NormalNoTitleLblTaDesc->ContLabel.TxtId)
        // &&
        // (SETTING_PIN2_NEW_VERIFYING_PUK2_CHK == g_SettingSecuritySettingMng.AccCodeChgStatus))
        else if (SETTING_PIN2_NEW_VERIFYING_PUK2_CHK == g_SettingSecuritySettingMng.AccCodeChgStatus)
        {
            // Setting_Set_Access_Code_Change_Status(SETTING_PIN2_NEW_ENTERING);
            // NormalNoTitleLblTaDesc->ContLabel.TxtId = PHONE_TEXT_ID_ENTER_NEW_PIN;
            // Setting_Set_Pin_Trying(FALSE);
            // Display_Setting_Enter_Security_Code_Update_Screen(NormalNoTitleLblTaDesc, 0);

            // it's a puk check request from external module
            if (SETTING_SECURITY_ACTION_EXT_PIN_CHK_NO_CNF ==
                g_SettingSecuritySettingMng.OperatingAction)
            {
                Nav_Forward(ACT_ID_SETTING_ENTER_SECURITY_CODE, g_SettingSecurityCheckCallerActId,NULL, NULL);
                Setting_Set_Operating_Action(SETTING_SECURITY_ACTION_NONE);
            }
            else if (SETTING_SECURITY_ACTION_EXT_PIN_CHK_WITH_CNF ==
                     g_SettingSecuritySettingMng.OperatingAction)
            {
                gp_SettingSecurityChkPinCnf(g_SettingSecuritySettingMng.OperatingSIM, SETTING_OK);
                // gp_SettingSecurityChkPinCnf = NULL;
                Setting_Set_Operating_Action(SETTING_SECURITY_ACTION_NONE);
            }
            else
            {   // set new PIN code successfully,reset PIN procedure
                Setting_Set_Access_Code_Change_Status(SETTING_PIN_OLD_ENTERING);
                Setting_Set_Pin_Trying(TRUE);

                Display_Setting_Done(ACT_ID_SETTING_ENTER_SECURITY_CODE, PHONE_TEXT_ID_DONE,ACT_ID_SETTING_SIM_SELECTION);
            }
        }
        // 2019-05-24, PUK checking needs new PIN together, end

        // 2019-05-24, changing PIN needs new PIN & old PIN both input, begin
        // else if (PHONE_TEXT_ID_VERIFY_NEW_PIN == NormalNoTitleLblTaDesc->ContLabel.TxtId)
        // {
        // if (  (SETTING_PIN_NEW_ENTERING == g_SettingSecuritySettingMng.AccCodeChgStatus)
        // ||
        // (SETTING_PIN_NEW_VERIFYING == g_SettingSecuritySettingMng.AccCodeChgStatus))
        // {
        // Display_Setting_Done(ACT_ID_SETTING_ENTER_SECURITY_CODE, PHONE_TEXT_ID_DONE,ACT_ID_SETTING_SIM_SELECTION);
        // }
        // }
        else if (SETTING_PIN_NEW_VERIFYING == g_SettingSecuritySettingMng.AccCodeChgStatus)
        {
            Setting_Set_Access_Code_Change_Status(SETTING_PIN_OLD_ENTERING);
            Setting_Set_Pin_Trying(TRUE);

            Display_Setting_Done(ACT_ID_SETTING_ENTER_SECURITY_CODE, PHONE_TEXT_ID_DONE,ACT_ID_SETTING_SIM_SELECTION);
        }
        else if (SETTING_PIN2_NEW_VERIFYING == g_SettingSecuritySettingMng.AccCodeChgStatus)
        {
            Setting_Set_Access_Code_Change_Status(SETTING_PIN2_OLD_ENTERING);
            Setting_Set_Pin_Trying(TRUE);

            Display_Setting_Done(ACT_ID_SETTING_ENTER_SECURITY_CODE, PHONE_TEXT_ID_DONE,ACT_ID_SETTING_SIM_SELECTION);
        }
        // 2019-05-24, changing PIN needs new PIN & old PIN both input, end
    }

    // Check incorrect and have rest tries, update screen & try the next time
    else if (TryResult > 0)
    {
        // pin check fail
        if (  (SETTING_PIN_OPERATION_PIN1 == g_SettingSecuritySettingMng.PinOperatingType)
           || (SETTING_PIN_OPERATION_PIN2 == g_SettingSecuritySettingMng.PinOperatingType))
        {
            Display_Setting_Enter_Security_Code_Update_Screen(NormalNoTitleLblTaDesc, TryResult);
        }
        // puk check fail, or pin check fail in case of changing pin
        // else if (PHONE_TEXT_ID_VERIFY_NEW_PIN == NormalNoTitleLblTaDesc->ContLabel.TxtId)
        // {
        // puk check fail
        else if (SETTING_PIN_OPERATION_PUK1_PIN_NEW_VERIFYING == g_SettingSecuritySettingMng.PinOperatingType)
        {
            if (MMI_MODEM_SIM_1 == g_SettingSecuritySettingMng.OperatingSIM)
            {
                NormalNoTitleLblTaDesc->ContLabel.TxtId = PHONE_TEXT_ID_ENTER_SIM1_PUK;
            }
            else
            {
                NormalNoTitleLblTaDesc->ContLabel.TxtId = PHONE_TEXT_ID_ENTER_SIM2_PUK;
            }

            Setting_Set_Pin_Operating_Type(SETTING_PIN_OPERATION_PUK1);
            Setting_Set_Pin_Trying(TRUE);
            Display_Setting_Enter_Security_Code_Update_Screen(NormalNoTitleLblTaDesc,TryResult);
        }
        else if (SETTING_PIN_NEW_VERIFYING_PUK_CHK == g_SettingSecuritySettingMng.AccCodeChgStatus)
        {
            if (MMI_MODEM_SIM_1 == g_SettingSecuritySettingMng.OperatingSIM)
            {
                NormalNoTitleLblTaDesc->ContLabel.TxtId = PHONE_TEXT_ID_ENTER_SIM1_PUK;
            }
            else
            {
                NormalNoTitleLblTaDesc->ContLabel.TxtId = PHONE_TEXT_ID_ENTER_SIM2_PUK;
            }
            Setting_Set_Access_Code_Change_Status(SETTING_PUK_ENTERING);
            Setting_Set_Pin_Trying(TRUE);
            Display_Setting_Error(ACT_ID_SETTING_ENTER_SECURITY_CODE,PHONE_TEXT_ID_CODE_ERROR,ACT_ID_SETTING_ENTER_SECURITY_CODE,TRUE);
        }
        else if (SETTING_PIN2_NEW_VERIFYING_PUK2_CHK == g_SettingSecuritySettingMng.AccCodeChgStatus)
        {
            if (MMI_MODEM_SIM_1 == g_SettingSecuritySettingMng.OperatingSIM)
            {
                NormalNoTitleLblTaDesc->ContLabel.TxtId = PHONE_TEXT_ID_ENTER_SIM1_PUK2;
            }
            else
            {
                NormalNoTitleLblTaDesc->ContLabel.TxtId = PHONE_TEXT_ID_ENTER_SIM2_PUK2;
            }
            Setting_Set_Access_Code_Change_Status(SETTING_PUK2_ENTERING);
            Setting_Set_Pin_Trying(TRUE);
            Display_Setting_Error(ACT_ID_SETTING_ENTER_SECURITY_CODE,PHONE_TEXT_ID_CODE_ERROR,ACT_ID_SETTING_ENTER_SECURITY_CODE,TRUE);
        }

        // pin check fail in case of changing pin
        else if (SETTING_PIN_NEW_VERIFYING == g_SettingSecuritySettingMng.AccCodeChgStatus)
        {
            Setting_Set_Access_Code_Change_Status(SETTING_PIN_OLD_ENTERING);
            Setting_Set_Pin_Trying(TRUE);
            if (MMI_MODEM_SIM_1 == g_SettingSecuritySettingMng.OperatingSIM)
            {
                NormalNoTitleLblTaDesc->ContLabel.TxtId = PHONE_TEXT_ID_ENTER_SIM1_PIN;
            }
            else
            {
                NormalNoTitleLblTaDesc->ContLabel.TxtId = PHONE_TEXT_ID_ENTER_SIM2_PIN;
            }

            Display_Setting_Error(ACT_ID_SETTING_ENTER_SECURITY_CODE,PHONE_TEXT_ID_CODE_ERROR,ACT_ID_SETTING_ENTER_SECURITY_CODE,TRUE);
        }
        else if (SETTING_PIN2_NEW_VERIFYING == g_SettingSecuritySettingMng.AccCodeChgStatus)
        {
            Setting_Set_Access_Code_Change_Status(SETTING_PIN2_OLD_ENTERING);
            Setting_Set_Pin_Trying(TRUE);
            if (MMI_MODEM_SIM_1 == g_SettingSecuritySettingMng.OperatingSIM)
            {
                NormalNoTitleLblTaDesc->ContLabel.TxtId = PHONE_TEXT_ID_ENTER_SIM1_PIN2;
            }
            else
            {
                NormalNoTitleLblTaDesc->ContLabel.TxtId = PHONE_TEXT_ID_ENTER_SIM2_PIN2;
            }

            Display_Setting_Error(ACT_ID_SETTING_ENTER_SECURITY_CODE,PHONE_TEXT_ID_CODE_ERROR,ACT_ID_SETTING_ENTER_SECURITY_CODE,TRUE);
        }
        // }
    }

    // PIN/PUK check incorrect and no rest try, then PIN checking->PUK checking, or PUK checking->PUK blocked
    else if (0 == TryResult)
    {
        if (SETTING_PIN_OPERATION_PIN1 == g_SettingSecuritySettingMng.PinOperatingType)
        {
            if (MMI_MODEM_SIM_1 == g_SettingSecuritySettingMng.OperatingSIM)
            {
                NormalNoTitleLblTaDesc->ContLabel.TxtId = PHONE_TEXT_ID_ENTER_SIM1_PUK;
            }
            else
            {
                NormalNoTitleLblTaDesc->ContLabel.TxtId = PHONE_TEXT_ID_ENTER_SIM2_PUK;
            }

            Setting_Set_Pin_Operating_Type(SETTING_PIN_OPERATION_PUK1);

            PinLockQuery.SimId   = g_SettingSecuritySettingMng.OperatingSIM;
            PinLockQuery.PinType = MMI_MODEM_PUK;
            MMI_Modem_Query_Pin_Lock(&PinLockQuery);

            Display_Setting_Enter_Security_Code_Update_Screen(NormalNoTitleLblTaDesc, PinLockQuery.RetriesLeft);
        }
        else if (SETTING_PIN_OPERATION_PIN2 == g_SettingSecuritySettingMng.PinOperatingType)
        {
            if (MMI_MODEM_SIM_1 == g_SettingSecuritySettingMng.OperatingSIM)
            {
                NormalNoTitleLblTaDesc->ContLabel.TxtId = PHONE_TEXT_ID_ENTER_SIM1_PUK2;
            }
            else
            {
                NormalNoTitleLblTaDesc->ContLabel.TxtId = PHONE_TEXT_ID_ENTER_SIM2_PUK2;
            }

            Display_Setting_Enter_Security_Code_Update_Screen(NormalNoTitleLblTaDesc, 10);
        }
        else if (SETTING_PIN_OPERATION_PUK1_PIN_NEW_VERIFYING == g_SettingSecuritySettingMng.PinOperatingType)
        {
            UI_Log_Out(UI_SUB_MODULE_SETTING, UI_LOG_LEVEL_TRACE_1, "*****PUK check failed*****\n");
            Setting_Set_Pin_Operating_Type(SETTING_PIN_OPERATION_OFF);

            // it's a puk check request from external module
            if (SETTING_SECURITY_ACTION_EXT_PIN_CHK_NO_CNF ==
                g_SettingSecuritySettingMng.OperatingAction)
            {
                Setting_Set_Operating_Action(SETTING_SECURITY_ACTION_NONE);
                Nav_Forward(ACT_ID_SETTING_ENTER_SECURITY_CODE, g_SettingSecurityCheckCallerActId,NULL, NULL);
            }
            else if (SETTING_SECURITY_ACTION_EXT_PIN_CHK_WITH_CNF ==
                     g_SettingSecuritySettingMng.OperatingAction)
            {
                Setting_Set_Operating_Action(SETTING_SECURITY_ACTION_NONE);
                Nav_Back(ACT_ID_SETTING_ENTER_SECURITY_CODE);
                gp_SettingSecurityChkPinCnf(g_SettingSecuritySettingMng.OperatingSIM, SETTING_ERROR);
                // gp_SettingSecurityChkPinCnf = NULL;
            }
            if (SETTING_SECURITY_ACTION_PIN_CODE_REQUEST ==
                g_SettingSecuritySettingMng.OperatingAction)
            {
                if (MMI_MODEM_SIM_1 == g_SettingSecuritySettingMng.OperatingSIM)
                {
                    Display_Setting_Security_Puk_Blocked(ACT_ID_SETTING_ENTER_SECURITY_CODE,PHONE_TEXT_ID_SIM1PUK_BLOCKED,g_SettingSecurityAutoNextActIdAfterDone);
                }
                else
                {
                    Display_Setting_Security_Puk_Blocked(ACT_ID_SETTING_ENTER_SECURITY_CODE,PHONE_TEXT_ID_SIM2PUK_BLOCKED,g_SettingSecurityAutoNextActIdAfterDone);
                }
            }
        }
        else if (SETTING_PIN_NEW_VERIFYING_PUK_CHK == g_SettingSecuritySettingMng.AccCodeChgStatus)
        {
            Setting_Set_Access_Code_Change_Status(SETTING_PIN_OLD_ENTERING);

            if (MMI_MODEM_SIM_1 == g_SettingSecuritySettingMng.OperatingSIM)
            {
                Display_Setting_Security_Puk_Blocked(ACT_ID_SETTING_ENTER_SECURITY_CODE,PHONE_TEXT_ID_SIM1PUK_BLOCKED,g_SettingSecurityAutoNextActIdAfterDone);
            }
            else
            {
                Display_Setting_Security_Puk_Blocked(ACT_ID_SETTING_ENTER_SECURITY_CODE,PHONE_TEXT_ID_SIM2PUK_BLOCKED,g_SettingSecurityAutoNextActIdAfterDone);
            }
        }
        else if (SETTING_PIN2_NEW_VERIFYING_PUK2_CHK == g_SettingSecuritySettingMng.AccCodeChgStatus)
        {
            Setting_Set_Access_Code_Change_Status(SETTING_PIN2_OLD_ENTERING);

            if (MMI_MODEM_SIM_1 == g_SettingSecuritySettingMng.OperatingSIM)
            {
                Display_Setting_Security_Puk_Blocked(ACT_ID_SETTING_ENTER_SECURITY_CODE,PHONE_TEXT_ID_SIM1PUK2_BLOCKED,g_SettingSecurityAutoNextActIdAfterDone);
            }
            else
            {
                Display_Setting_Security_Puk_Blocked(ACT_ID_SETTING_ENTER_SECURITY_CODE,PHONE_TEXT_ID_SIM2PUK2_BLOCKED,g_SettingSecurityAutoNextActIdAfterDone);
            }
        }
        else if (SETTING_PIN_NEW_VERIFYING == g_SettingSecuritySettingMng.AccCodeChgStatus)
        {
            Setting_Set_Access_Code_Change_Status(SETTING_PIN_OLD_ENTERING);
            Display_Setting_Error(ACT_ID_SETTING_ENTER_SECURITY_CODE,PHONE_TEXT_ID_CODE_ERROR,ACT_ID_SETTING_SIM_SELECTION,TRUE);
        }
        else if (SETTING_PIN2_NEW_VERIFYING == g_SettingSecuritySettingMng.AccCodeChgStatus)
        {
            Setting_Set_Access_Code_Change_Status(SETTING_PIN2_OLD_ENTERING);
            Display_Setting_Error(ACT_ID_SETTING_ENTER_SECURITY_CODE,PHONE_TEXT_ID_CODE_ERROR,ACT_ID_SETTING_SIM_SELECTION,TRUE);
        }
    }
} /* Display_Setting_Enter_Security_Code_Handle_PinPuk_Try_Result */

/**
 *
 * Callback of Setting_Enter_Security_Code, KeyCb, OK, in case of PIN checking
 * param (in) obj: lv_obj_t*
 *       (in) key_sta: UI_KEY_STATUS
 *       (in) key_val: UI_KEY_VALUE
 * return UINT8: 0--call system handling outside
 *               1--handled inside
 */
UINT8 Display_Setting_Enter_Security_Code_KeyCb_OK_Pin_Chk(lv_obj_t *obj, UI_KEY_STATUS key_sta,
                                                           UI_KEY_VALUE key_val)
{
    BOOL                              PinReqStatus;
    UINT8                             TryLeftCnt;

    UI_Normal_NoTitle_Label_Ta_Desc_t *NormalNoTitleLblTaDesc;

    NormalNoTitleLblTaDesc =
        (UI_Normal_NoTitle_Label_Ta_Desc_t *)gp_SettingSecuritySettingCurUIDesc;

    if (0 != g_SettingSecurityPinCodeTaRestCharacters)
    {
        // In case of invalid code length, need give a waring to user here?
        Display_Setting_Error(ACT_ID_SETTING_ENTER_SECURITY_CODE, PHONE_TEXT_ID_LEN_ERROR,ACT_ID_SETTING_ENTER_SECURITY_CODE, FALSE);
    }
    // in case of valid code length
    else
    {
        // Try the input PIN code
        // PIN = Hal_Mem_Alloc(10);
        // strcpy(PIN, lv_ta_get_text(NormalNoTitleLblTaDesc->ContTa.TextArea));
        // TryLeftCnt = MMI_Modem_Try_Pin_Req(g_SettingSecuritySettingMng.OperatingSIM, PIN);
        // Display_Setting_Enter_Security_Code_Handle_PinPuk_Try_Result(TryLeftCnt);
        if (SETTING_SECURITY_ACTION_PIN_CODE_REQUEST == g_SettingSecuritySettingMng.OperatingAction)
        {
            // update PIN request status: OFF->ON, or ON->OFF, then display setting_done
            if (SETTING_PIN_OPERATION_PIN1 == g_SettingSecuritySettingMng.PinOperatingType)
            {
                // update to SIM
                if (FALSE ==
                    g_SettingSecuritySettingMng.IsPinRequest[g_SettingSecuritySettingMng.
                                                                 OperatingSIM])
                {
                    PinReqStatus = TRUE;
                }
                else
                {
                    PinReqStatus = FALSE;
                }
                TryLeftCnt =
                    Setting_Set_Pin_Request_Status(PinReqStatus,g_SettingSecuritySettingMng.OperatingSIM,lv_textarea_get_text(NormalNoTitleLblTaDesc->ContTa.TextArea));
                Display_Setting_Enter_Security_Code_Handle_PinPuk_Try_Result(TryLeftCnt);
            }
        }
        else if (SETTING_SECURITY_ACTION_EXT_PIN_CHK_WITH_CNF == g_SettingSecuritySettingMng.OperatingAction)
        {
            TryLeftCnt = MMI_Modem_Try_Pin_Req(g_SettingSecuritySettingMng.OperatingSIM, (INT8 *)lv_textarea_get_text(NormalNoTitleLblTaDesc->ContTa.TextArea));
            Display_Setting_Enter_Security_Code_Handle_PinPuk_Try_Result(TryLeftCnt);
        }
    }
    return(1);
} /* Display_Setting_Enter_Security_Code_KeyCb_OK_Pin_Chk */

/**
 *
 * Callback of Setting_Enter_Security_Code, KeyCb, OK, in case of PIN2 checking
 * param (in) obj: lv_obj_t*
 *       (in) key_sta: UI_KEY_STATUS
 *       (in) key_val: UI_KEY_VALUE
 * return UINT8: 0--call system handling outside
 *               1--handled inside
 */
UINT8 Display_Setting_Enter_Security_Code_KeyCb_OK_Pin2_Chk(lv_obj_t *obj, UI_KEY_STATUS key_sta,
                                                            UI_KEY_VALUE key_val)
{
    UINT8                             TryLeftCnt;
    INT8                              *PIN2;

    UI_Normal_NoTitle_Label_Ta_Desc_t *NormalNoTitleLblTaDesc;

    NormalNoTitleLblTaDesc =
        (UI_Normal_NoTitle_Label_Ta_Desc_t *)gp_SettingSecuritySettingCurUIDesc;

    if (0 != g_SettingSecurityPinCodeTaRestCharacters)
    {
        // In case of invalid code length, need give a waring to user here?
        Display_Setting_Error(ACT_ID_SETTING_ENTER_SECURITY_CODE, PHONE_TEXT_ID_LEN_ERROR,ACT_ID_SETTING_ENTER_SECURITY_CODE, FALSE);
    }
    // in case of valid code length
    else
    {
        // Try the input PIN code
        PIN2 = Hal_Mem_Alloc(10);
        strcpy(PIN2, lv_textarea_get_text(NormalNoTitleLblTaDesc->ContTa.TextArea));
        TryLeftCnt = MMI_Modem_Try_Pin2_Req(g_SettingSecuritySettingMng.OperatingSIM, PIN2);
        Display_Setting_Enter_Security_Code_Handle_PinPuk_Try_Result(TryLeftCnt);
    }
    return(1);
}

/**
 *
 * Callback of Setting_Enter_Security_Code, KeyCb, OK, in case of PUK checking
 * param (in) obj: lv_obj_t*
 *       (in) key_sta: UI_KEY_STATUS
 *       (in) key_val: UI_KEY_VALUE
 * return UINT8: 0--call system handling outside
 *               1--handled inside
 */
UINT8 Display_Setting_Enter_Security_Code_KeyCb_OK_Puk_Chk(lv_obj_t *obj, UI_KEY_STATUS key_sta,
                                                           UI_KEY_VALUE key_val)
{
    INT8                              *PUK;

    UI_Normal_NoTitle_Label_Ta_Desc_t *NormalNoTitleLblTaDesc;

    NormalNoTitleLblTaDesc =
        (UI_Normal_NoTitle_Label_Ta_Desc_t *)gp_SettingSecuritySettingCurUIDesc;

    if (0 != g_SettingSecurityPinCodeTaRestCharacters)
    {
        // In case of invalid code length, need give a waring to user here?
        Display_Setting_Error(ACT_ID_SETTING_ENTER_SECURITY_CODE, PHONE_TEXT_ID_LEN_ERROR,ACT_ID_SETTING_ENTER_SECURITY_CODE, FALSE);
    }
    // in case of valid code length
    else
    {
        // Try the input PIN code
        PUK = Hal_Mem_Alloc(10);
        strcpy(PUK, lv_textarea_get_text(NormalNoTitleLblTaDesc->ContTa.TextArea));

        // 2019-05-24, PUK checking needs new PIN together, begin
        // TryLeftCnt = MMI_Modem_Try_Puk_Req(g_SettingSecuritySettingMng.OperatingSIM, PUK);
        // Display_Setting_Enter_Security_Code_Handle_PinPuk_Try_Result(TryLeftCnt);
        Setting_Store_Puk_code((INT8 *)lv_textarea_get_text(NormalNoTitleLblTaDesc->ContTa.TextArea));

        if (  (SETTING_SECURITY_ACTION_EXT_PIN_CHK_WITH_CNF == g_SettingSecuritySettingMng.OperatingAction)
           || (SETTING_SECURITY_ACTION_EXT_PIN_CHK_NO_CNF == g_SettingSecuritySettingMng.OperatingAction)
           || (SETTING_SECURITY_ACTION_PIN_CODE_REQUEST == g_SettingSecuritySettingMng.OperatingAction))
        {
            Setting_Set_Pin_Operating_Type(SETTING_PIN_OPERATION_PUK1_PIN_NEW_ENTERING);
        }
        else
        {
            Setting_Set_Access_Code_Change_Status(SETTING_PIN_NEW_ENTERING_PUK_CHK);
        }
        Setting_Set_Pin_Trying(FALSE);
        NormalNoTitleLblTaDesc->ContLabel.TxtId = PHONE_TEXT_ID_ENTER_NEW_PIN;
        Display_Setting_Enter_Security_Code_Update_Screen(NormalNoTitleLblTaDesc, 0);
        // 2019-05-24, PUK checking needs new PIN together, end
    }
    return(1);
} /* Display_Setting_Enter_Security_Code_KeyCb_OK_Puk_Chk */

/**
 *
 * Callback of Setting_Enter_Security_Code, KeyCb, OK, in case of PUK2 checking
 * param (in) obj: lv_obj_t*
 *       (in) key_sta: UI_KEY_STATUS
 *       (in) key_val: UI_KEY_VALUE
 * return UINT8: 0--call system handling outside
 *               1--handled inside
 */
UINT8 Display_Setting_Enter_Security_Code_KeyCb_OK_Puk2_Chk(lv_obj_t *obj, UI_KEY_STATUS key_sta,
                                                            UI_KEY_VALUE key_val)
{
    INT8                              *PUK2;

    UI_Normal_NoTitle_Label_Ta_Desc_t *NormalNoTitleLblTaDesc;

    NormalNoTitleLblTaDesc =
        (UI_Normal_NoTitle_Label_Ta_Desc_t *)gp_SettingSecuritySettingCurUIDesc;

    if (0 != g_SettingSecurityPinCodeTaRestCharacters)
    {
        // In case of invalid code length, need give a waring to user here?
        Display_Setting_Error(ACT_ID_SETTING_ENTER_SECURITY_CODE, PHONE_TEXT_ID_LEN_ERROR,ACT_ID_SETTING_ENTER_SECURITY_CODE, FALSE);
    }
    // in case of valid code length
    else
    {
        // Try the input PIN code
        PUK2 = Hal_Mem_Alloc(10);
        strcpy(PUK2, lv_textarea_get_text(NormalNoTitleLblTaDesc->ContTa.TextArea));

        // 2019-05-24, PUK checking needs new PIN together, begin
        // TryLeftCnt = MMI_Modem_Try_Puk2_Req(g_SettingSecuritySettingMng.OperatingSIM, PUK2);
        // Display_Setting_Enter_Security_Code_Handle_PinPuk_Try_Result(TryLeftCnt);
        Setting_Store_Puk_code((INT8 *)lv_textarea_get_text(NormalNoTitleLblTaDesc->ContTa.TextArea));
        Setting_Set_Access_Code_Change_Status(SETTING_PIN2_NEW_ENTERING_PUK2_CHK);
        NormalNoTitleLblTaDesc->ContLabel.TxtId = PHONE_TEXT_ID_ENTER_NEW_PIN2;
        Setting_Set_Pin_Trying(FALSE);
        Display_Setting_Enter_Security_Code_Update_Screen(NormalNoTitleLblTaDesc, 0);
        // 2019-05-24, PUK checking needs new PIN together, end
    }
    return(1);
}

/**
 *
 * Callback of Setting_Enter_Security_Code, KeyCb, OK, in case of enter old PIN/PIN2
 * param (in) obj: lv_obj_t*
 *       (in) key_sta: UI_KEY_STATUS
 *       (in) key_val: UI_KEY_VALUE
 * return UINT8: 0--call system handling outside
 *               1--handled inside
 */
UINT8 Display_Setting_Enter_Security_Code_KeyCb_OK_Enter_Old_Pin(lv_obj_t      *obj,
                                                                 UI_KEY_STATUS key_sta,
                                                                 UI_KEY_VALUE  key_val)
{
    INT8                              *PIN;
    INT8                              *PIN2;

    UI_Normal_NoTitle_Label_Ta_Desc_t *NormalNoTitleLblTaDesc;

    NormalNoTitleLblTaDesc =
        (UI_Normal_NoTitle_Label_Ta_Desc_t *)gp_SettingSecuritySettingCurUIDesc;

    if (0 != g_SettingSecurityPinCodeTaRestCharacters)
    {
        // In case of invalid code length, need give a waring to user here?
        Display_Setting_Error(ACT_ID_SETTING_ENTER_SECURITY_CODE, PHONE_TEXT_ID_LEN_ERROR,ACT_ID_SETTING_ENTER_SECURITY_CODE, FALSE);
    }
    // in case of valid code length
    else
    {
        // PIN code
        if (SETTING_PIN_OLD_ENTERING == g_SettingSecuritySettingMng.AccCodeChgStatus)
        {
            // Try the input PIN code
            PIN = Hal_Mem_Alloc(10);
            strcpy(PIN, lv_textarea_get_text(NormalNoTitleLblTaDesc->ContTa.TextArea));
            // 2019-05-24, changing PIN needs new PIN & old PIN both input, begin
            Setting_Store_Old_Pin_code(PIN);
            // TryLeftCnt = MMI_Modem_Try_Pin_Req(g_SettingSecuritySettingMng.OperatingSIM, PIN);
            // if (MMI_MODEM_PIN_CHECK_OK == TryLeftCnt)
            // {
            Setting_Set_Access_Code_Change_Status(SETTING_PIN_NEW_ENTERING);
            Setting_Set_Pin_Trying(FALSE);
            NormalNoTitleLblTaDesc->ContLabel.TxtId = PHONE_TEXT_ID_ENTER_NEW_PIN;
            Display_Setting_Enter_Security_Code_Update_Screen(NormalNoTitleLblTaDesc, 0);
            // }
            // else
            // {
            // Display_Setting_Error(ACT_ID_SETTING_ENTER_SECURITY_CODE,PHONE_TEXT_ID_CODE_ERROR,ACT_ID_SETTING_SIM_SELECTION,TRUE);
            // }
            // 2019-05-24, changing PIN needs new PIN & old PIN both input, end
        }
        // PIN2 code
        else if (SETTING_PIN2_OLD_ENTERING == g_SettingSecuritySettingMng.AccCodeChgStatus)
        {
            // Try the input PIN2 code
            PIN2 = Hal_Mem_Alloc(10);
            strcpy(PIN2, lv_textarea_get_text(NormalNoTitleLblTaDesc->ContTa.TextArea));
            // 2019-05-24, changing PIN needs new PIN & old PIN both input, begin
            Setting_Store_Old_Pin_code(PIN2);
            // TryLeftCnt = MMI_Modem_Try_Pin2_Req(g_SettingSecuritySettingMng.OperatingSIM, PIN2);
            // if (MMI_MODEM_PIN_CHECK_OK == TryLeftCnt)
            // {
            Setting_Set_Access_Code_Change_Status(SETTING_PIN2_NEW_ENTERING);
            Setting_Set_Pin_Trying(FALSE);
            NormalNoTitleLblTaDesc->ContLabel.TxtId = PHONE_TEXT_ID_ENTER_NEW_PIN2;
            Display_Setting_Enter_Security_Code_Update_Screen(NormalNoTitleLblTaDesc, 0);
            // }
            // else
            // {
            // Display_Setting_Error(ACT_ID_SETTING_ENTER_SECURITY_CODE,PHONE_TEXT_ID_CODE_ERROR,ACT_ID_SETTING_SIM_SELECTION,TRUE);
            // }
            // 2019-05-24, changing PIN needs new PIN & old PIN both input, end
        }
    }
    return(1);
} /* Display_Setting_Enter_Security_Code_KeyCb_OK_Enter_Old_Pin */

/**
 *
 * Callback of Setting_Enter_Security_Code, KeyCb, OK, in case of enter new PIN/PIN2
 * param (in) obj: lv_obj_t*
 *       (in) key_sta: UI_KEY_STATUS
 *       (in) key_val: UI_KEY_VALUE
 * return UINT8: 0--call system handling outside
 *               1--handled inside
 */
UINT8 Display_Setting_Enter_Security_Code_KeyCb_OK_Enter_New_Pin(lv_obj_t      *obj,
                                                                 UI_KEY_STATUS key_sta,
                                                                 UI_KEY_VALUE  key_val)
{
    UI_Normal_NoTitle_Label_Ta_Desc_t *NormalNoTitleLblTaDesc;

    NormalNoTitleLblTaDesc =
        (UI_Normal_NoTitle_Label_Ta_Desc_t *)gp_SettingSecuritySettingCurUIDesc;

    if (0 != g_SettingSecurityPinCodeTaRestCharacters)
    {
        // In case of invalid code length, need give a waring to user here?
        Display_Setting_Error(ACT_ID_SETTING_ENTER_SECURITY_CODE, PHONE_TEXT_ID_LEN_ERROR,ACT_ID_SETTING_ENTER_SECURITY_CODE, FALSE);
    }
    // in case of valid code length
    else
    {
        // PIN
        Setting_Set_New_Pin_code((INT8 *)lv_textarea_get_text(NormalNoTitleLblTaDesc->ContTa.TextArea));
        if (SETTING_PIN_NEW_ENTERING == g_SettingSecuritySettingMng.AccCodeChgStatus)
        {
            Setting_Set_Access_Code_Change_Status(SETTING_PIN_NEW_VERIFYING);
            NormalNoTitleLblTaDesc->ContLabel.TxtId = PHONE_TEXT_ID_VERIFY_NEW_PIN;
        }
        // PIN2
        else if (SETTING_PIN2_NEW_ENTERING == g_SettingSecuritySettingMng.AccCodeChgStatus)
        {
            Setting_Set_Access_Code_Change_Status(SETTING_PIN2_NEW_VERIFYING);
            NormalNoTitleLblTaDesc->ContLabel.TxtId = PHONE_TEXT_ID_VERIFY_NEW_PIN2;
        }
        // 2019-05-24, PUK checking needs new PIN together, begin
        else if (SETTING_PIN_NEW_ENTERING_PUK_CHK == g_SettingSecuritySettingMng.AccCodeChgStatus)
        {
            Setting_Set_Access_Code_Change_Status(SETTING_PIN_NEW_VERIFYING_PUK_CHK);
            NormalNoTitleLblTaDesc->ContLabel.TxtId = PHONE_TEXT_ID_VERIFY_NEW_PIN;
        }
        else if (SETTING_PIN2_NEW_ENTERING_PUK2_CHK == g_SettingSecuritySettingMng.AccCodeChgStatus)
        {
            Setting_Set_Access_Code_Change_Status(SETTING_PIN2_NEW_VERIFYING_PUK2_CHK);
            NormalNoTitleLblTaDesc->ContLabel.TxtId = PHONE_TEXT_ID_VERIFY_NEW_PIN2;
        }
        else if (SETTING_PIN_OPERATION_PUK1_PIN_NEW_ENTERING == g_SettingSecuritySettingMng.PinOperatingType)
        {
            Setting_Set_Pin_Operating_Type(SETTING_PIN_OPERATION_PUK1_PIN_NEW_VERIFYING);
            NormalNoTitleLblTaDesc->ContLabel.TxtId = PHONE_TEXT_ID_VERIFY_NEW_PIN;
        }
        // 2019-05-24, PUK checking needs new PIN together, end
        Display_Setting_Enter_Security_Code_Update_Screen(NormalNoTitleLblTaDesc, 0);
    }
    return(1);
} /* Display_Setting_Enter_Security_Code_KeyCb_OK_Enter_New_Pin */

/**
 *
 * Callback of Setting_Enter_Security_Code, KeyCb, OK, in case of verify new PIN/PIN2
 * param (in) obj: lv_obj_t*
 *       (in) key_sta: UI_KEY_STATUS
 *       (in) key_val: UI_KEY_VALUE
 * return UINT8: 0--call system handling outside
 *               1--handled inside
 */
UINT8 Display_Setting_Enter_Security_Code_KeyCb_OK_Verify_New_Pin(lv_obj_t      *obj,
                                                                  UI_KEY_STATUS key_sta,
                                                                  UI_KEY_VALUE  key_val)
{
    UI_Normal_NoTitle_Label_Ta_Desc_t *NormalNoTitleLblTaDesc;
    INT8                              *PIN, *PUK, *OldPIN;
    INT8                              *PIN2, *PUK2, *OldPIN2;
    UINT8                             TryLeftCnt;

    NormalNoTitleLblTaDesc =
        (UI_Normal_NoTitle_Label_Ta_Desc_t *)gp_SettingSecuritySettingCurUIDesc;

    if (0 != g_SettingSecurityPinCodeTaRestCharacters)
    {
        // In case of invalid code length, need give a waring to user here?
        Display_Setting_Error(ACT_ID_SETTING_ENTER_SECURITY_CODE, PHONE_TEXT_ID_LEN_ERROR,ACT_ID_SETTING_ENTER_SECURITY_CODE, FALSE);
    }
    // in case of valid code length
    else
    {
        // new PIN code verify ok
        if (TRUE ==
            Setting_Verify_New_Pin_code((INT8 *)lv_textarea_get_text(NormalNoTitleLblTaDesc->ContTa.
                                                                   TextArea)))
        {
            // 2019-05-24, changing PIN needs new PIN & old PIN both input, begin
            if (SETTING_PIN_NEW_VERIFYING == g_SettingSecuritySettingMng.AccCodeChgStatus)
            {       // PIN
                PIN = Hal_Mem_Alloc(10);
                strcpy(PIN, lv_textarea_get_text(NormalNoTitleLblTaDesc->ContTa.TextArea));
                OldPIN = Hal_Mem_Alloc(10);
                Hal_Mem_Copy(OldPIN, g_SettingSecuritySettingMng.OldPinCode,SETTING_SECURITY_PIN_CODE_LEN);
                OldPIN[SETTING_SECURITY_PIN_CODE_LEN] = 0;
                TryLeftCnt                            = MMI_Modem_Change_Pin_Req(g_SettingSecuritySettingMng.OperatingSIM, PIN,OldPIN);
                Display_Setting_Enter_Security_Code_Handle_PinPuk_Try_Result(TryLeftCnt);
            }
            else if (SETTING_PIN2_NEW_VERIFYING == g_SettingSecuritySettingMng.AccCodeChgStatus)
            {       // PIN2
                PIN2 = Hal_Mem_Alloc(10);
                strcpy(PIN2, lv_textarea_get_text(NormalNoTitleLblTaDesc->ContTa.TextArea));
                OldPIN2 = Hal_Mem_Alloc(10);
                Hal_Mem_Copy(OldPIN2, g_SettingSecuritySettingMng.OldPinCode,SETTING_SECURITY_PIN_CODE_LEN);
                OldPIN2[SETTING_SECURITY_PIN_CODE_LEN] = 0;
                TryLeftCnt                             = MMI_Modem_Change_Pin2_Req(g_SettingSecuritySettingMng.OperatingSIM, PIN2,OldPIN2);
                Display_Setting_Enter_Security_Code_Handle_PinPuk_Try_Result(TryLeftCnt);
            }
            // 2019-05-24, changing PIN needs new PIN & old PIN both input, end

            // 2019-05-24, PUK checking needs new PIN together, begin
            else if (  (SETTING_PIN_NEW_VERIFYING_PUK_CHK == g_SettingSecuritySettingMng.AccCodeChgStatus)
                    || (SETTING_PIN_OPERATION_PUK1_PIN_NEW_VERIFYING == g_SettingSecuritySettingMng.PinOperatingType))
            {       // PUK+PIN
                PIN = Hal_Mem_Alloc(10);
                strcpy(PIN, lv_textarea_get_text(NormalNoTitleLblTaDesc->ContTa.TextArea));
                PUK = Hal_Mem_Alloc(10);
                Hal_Mem_Copy(PUK, g_SettingSecuritySettingMng.PukCode, SETTING_SECURITY_PUK_CODE_LEN);
                PUK[SETTING_SECURITY_PUK_CODE_LEN] = 0;
                TryLeftCnt                         = MMI_Modem_Try_Puk_Req(g_SettingSecuritySettingMng.OperatingSIM,PUK,PIN);
                Display_Setting_Enter_Security_Code_Handle_PinPuk_Try_Result(TryLeftCnt);
            }
            else if (SETTING_PIN2_NEW_VERIFYING_PUK2_CHK ==
                     g_SettingSecuritySettingMng.AccCodeChgStatus)
            {       // PUK2+PIN2
                PIN2 = Hal_Mem_Alloc(10);
                strcpy(PIN2, lv_textarea_get_text(NormalNoTitleLblTaDesc->ContTa.TextArea));
                PUK2 = Hal_Mem_Alloc(10);
                Hal_Mem_Copy(PUK2, g_SettingSecuritySettingMng.PukCode, SETTING_SECURITY_PUK_CODE_LEN);
                PUK2[SETTING_SECURITY_PUK_CODE_LEN] = 0;
                TryLeftCnt                          =
                    MMI_Modem_Try_Puk2_Req(g_SettingSecuritySettingMng.OperatingSIM, PUK2, PIN2);
                Display_Setting_Enter_Security_Code_Handle_PinPuk_Try_Result(TryLeftCnt);
            }

            // it's a puk check request from external module
            // if (SETTING_SECURITY_ACTION_EXT_PIN_CHK_NO_CNF == g_SettingSecuritySettingMng.OperatingAction)
            // {
            // Nav_Forward(ACT_ID_SETTING_ENTER_SECURITY_CODE, g_SettingSecurityCheckCallerActId, NULL, NULL);
            // Setting_Set_Operating_Action(SETTING_SECURITY_ACTION_NONE);
            // }
            // else if (SETTING_SECURITY_ACTION_EXT_PIN_CHK_WITH_CNF == g_SettingSecuritySettingMng.OperatingAction)
            // {
            // gp_SettingSecurityChkPinCnf(g_SettingSecuritySettingMng.OperatingSIM, SETTING_OK);
            // gp_SettingSecurityChkPinCnf = NULL;
            // Setting_Set_Operating_Action(SETTING_SECURITY_ACTION_NONE);
            // }
            // else
            // {
            // Display_Setting_Done(ACT_ID_SETTING_ENTER_SECURITY_CODE, PHONE_TEXT_ID_DONE, ACT_ID_SETTING_SIM_SELECTION);
            // }
            // 2019-05-24, PUK checking needs new PIN together, end
        }

        // code verify fail
        else
        {
            // if it's a puk check request from external module,
            // return to external caller even if PIN not set successfully after PUK check ok
            if (SETTING_SECURITY_ACTION_EXT_PIN_CHK_NO_CNF ==
                g_SettingSecuritySettingMng.OperatingAction)
            {
                Nav_Forward(ACT_ID_SETTING_ENTER_SECURITY_CODE, g_SettingSecurityCheckCallerActId,NULL, NULL);
                Setting_Set_Operating_Action(SETTING_SECURITY_ACTION_NONE);
            }
            else if (  (SETTING_SECURITY_ACTION_EXT_PIN_CHK_WITH_CNF ==
                        g_SettingSecuritySettingMng.OperatingAction)
                    || (SETTING_SECURITY_ACTION_PIN_CODE_REQUEST ==
                        g_SettingSecuritySettingMng.OperatingAction))
            {
                // gp_SettingSecurityChkPinCnf(g_SettingSecuritySettingMng.OperatingSIM, SETTING_OK);
                // gp_SettingSecurityChkPinCnf = NULL;
                // Setting_Set_Operating_Action(SETTING_SECURITY_ACTION_NONE);
                // recheck PIN code
                Setting_Set_Pin_Operating_Type(SETTING_PIN_OPERATION_PUK1_PIN_NEW_ENTERING);
                NormalNoTitleLblTaDesc->ContLabel.TxtId = PHONE_TEXT_ID_ENTER_NEW_PIN;
                Display_Setting_Enter_Security_Code_Update_Screen(NormalNoTitleLblTaDesc, 0);
            }
            else
            {
                if (SETTING_PIN_NEW_VERIFYING == g_SettingSecuritySettingMng.AccCodeChgStatus)
                {
                    Setting_Set_Access_Code_Change_Status(SETTING_PIN_NEW_ENTERING);
                    NormalNoTitleLblTaDesc->ContLabel.TxtId = PHONE_TEXT_ID_ENTER_NEW_PIN;
                }
                else if (SETTING_PIN2_NEW_VERIFYING == g_SettingSecuritySettingMng.AccCodeChgStatus)
                {
                    Setting_Set_Access_Code_Change_Status(SETTING_PIN2_NEW_ENTERING);
                    NormalNoTitleLblTaDesc->ContLabel.TxtId = PHONE_TEXT_ID_ENTER_NEW_PIN2;
                }
                else if (SETTING_PIN_NEW_VERIFYING_PUK_CHK == g_SettingSecuritySettingMng.AccCodeChgStatus)
                {
                    Setting_Set_Access_Code_Change_Status(SETTING_PIN_NEW_ENTERING_PUK_CHK);
                    NormalNoTitleLblTaDesc->ContLabel.TxtId = PHONE_TEXT_ID_ENTER_NEW_PIN;
                }
                else if (SETTING_PIN2_NEW_VERIFYING_PUK2_CHK == g_SettingSecuritySettingMng.AccCodeChgStatus)
                {
                    Setting_Set_Access_Code_Change_Status(SETTING_PIN2_NEW_ENTERING_PUK2_CHK);
                    NormalNoTitleLblTaDesc->ContLabel.TxtId = PHONE_TEXT_ID_ENTER_NEW_PIN2;
                }

                Display_Setting_Error(ACT_ID_SETTING_ENTER_SECURITY_CODE,PHONE_TEXT_ID_CODE_NOT_MATCH,ACT_ID_SETTING_ENTER_SECURITY_CODE,TRUE);
            }
        }
    }

    return(1);
} /* Display_Setting_Enter_Security_Code_KeyCb_OK_Verify_New_Pin */

/**
 *
 * Callback of Setting_Enter_Security_Code, KeyCb, OK, in case of enter old security code
 * param (in) obj: lv_obj_t*
 *       (in) key_sta: UI_KEY_STATUS
 *       (in) key_val: UI_KEY_VALUE
 * return UINT8: 0--call system handling outside
 *               1--handled inside
 */
UINT8 Display_Setting_Enter_Security_Code_KeyCb_OK_Enter_Old_Security_Code(lv_obj_t      *obj,
                                                                           UI_KEY_STATUS key_sta,
                                                                           UI_KEY_VALUE  key_val)
{
    UI_Normal_NoTitle_Label_Ta_Desc_t *NormalNoTitleLblTaDesc;

    NormalNoTitleLblTaDesc =
        (UI_Normal_NoTitle_Label_Ta_Desc_t *)gp_SettingSecuritySettingCurUIDesc;

    if (0 != g_SettingSecurityPinCodeTaRestCharacters)
    {
        // In case of invalid code length, need give a waring to user here?
        Display_Setting_Error(ACT_ID_SETTING_ENTER_SECURITY_CODE, PHONE_TEXT_ID_LEN_ERROR,ACT_ID_SETTING_ENTER_SECURITY_CODE, FALSE);
    }
    // in case of valid code length
    else
    {
        // old security code match
        if (TRUE ==
            Setting_Verify_Security_code((INT8 *)lv_textarea_get_text(NormalNoTitleLblTaDesc->ContTa.
                                                                    TextArea)))
        {
            // start enter new code
            Setting_Set_Access_Code_Change_Status(SETTING_SECURITY_NEW_ENTERING);
            NormalNoTitleLblTaDesc->ContLabel.TxtId = PHONE_TEXT_ID_ENTER_NEW_SECURITY;
            Display_Setting_Enter_Security_Code_Update_Screen(NormalNoTitleLblTaDesc, 0);
        }
        // not match
        else
        {
            Display_Setting_Error(ACT_ID_SETTING_ENTER_SECURITY_CODE, PHONE_TEXT_ID_CODE_ERROR,ACT_ID_SETTING_ENTER_SECURITY_CODE, TRUE);
        }
    }
    return(1);
}

/**
 *
 * Callback of Setting_Enter_Security_Code, KeyCb, OK, in case of enter new security code
 * param (in) obj: lv_obj_t*
 *       (in) key_sta: UI_KEY_STATUS
 *       (in) key_val: UI_KEY_VALUE
 * return UINT8: 0--call system handling outside
 *               1--handled inside
 */
UINT8 Display_Setting_Enter_Security_Code_KeyCb_OK_Enter_New_Security_Code(lv_obj_t      *obj,
                                                                           UI_KEY_STATUS key_sta,
                                                                           UI_KEY_VALUE  key_val)
{
    UI_Normal_NoTitle_Label_Ta_Desc_t *NormalNoTitleLblTaDesc;

    NormalNoTitleLblTaDesc =
        (UI_Normal_NoTitle_Label_Ta_Desc_t *)gp_SettingSecuritySettingCurUIDesc;

    if (0 != g_SettingSecurityPinCodeTaRestCharacters)
    {
        // In case of invalid code length, need give a waring to user here?
        Display_Setting_Error(ACT_ID_SETTING_ENTER_SECURITY_CODE, PHONE_TEXT_ID_LEN_ERROR,ACT_ID_SETTING_ENTER_SECURITY_CODE, FALSE);
    }
    // in case of valid code length
    else
    {
        // save the new code
        Hal_Mem_Copy(g_SettingSecuritySettingMng.NewSecurityCode,lv_textarea_get_text(NormalNoTitleLblTaDesc->ContTa.TextArea), NV_SETTING_SECURITY_CODE_LEN);

        // switch to verify code screen
        Setting_Set_Access_Code_Change_Status(SETTING_SECURITY_NEW_VERIFYING);
        NormalNoTitleLblTaDesc->ContLabel.TxtId = PHONE_TEXT_ID_VERIFY_NEW_SECURITY;
        Display_Setting_Enter_Security_Code_Update_Screen(NormalNoTitleLblTaDesc, 0);
    }
    return(1);
}

/**
 *
 * Callback of Setting_Enter_Security_Code, KeyCb, OK, in case of verify new security code
 * param (in) obj: lv_obj_t*
 *       (in) key_sta: UI_KEY_STATUS
 *       (in) key_val: UI_KEY_VALUE
 * return UINT8: 0--call system handling outside
 *               1--handled inside
 */
UINT8 Display_Setting_Enter_Security_Code_KeyCb_OK_Verify_New_Security_Code(lv_obj_t      *obj,
                                                                            UI_KEY_STATUS key_sta,
                                                                            UI_KEY_VALUE  key_val)
{
    UI_Normal_NoTitle_Label_Ta_Desc_t *NormalNoTitleLblTaDesc;

    NormalNoTitleLblTaDesc =
        (UI_Normal_NoTitle_Label_Ta_Desc_t *)gp_SettingSecuritySettingCurUIDesc;

    if (0 != g_SettingSecurityPinCodeTaRestCharacters)
    {
        // In case of invalid code length, need give a waring to user here?
        Display_Setting_Error(ACT_ID_SETTING_ENTER_SECURITY_CODE, PHONE_TEXT_ID_LEN_ERROR,ACT_ID_SETTING_ENTER_SECURITY_CODE, FALSE);
    }
    // in case of valid code length
    else
    {
        // new code code verify ok
        if (TRUE ==
            Setting_Verify_New_Security_code((INT8 *)lv_textarea_get_text(NormalNoTitleLblTaDesc->ContTa.
                                                                        TextArea)))
        {
            // store the new code
            Setting_Set_Security_code((INT8 *)lv_textarea_get_text(NormalNoTitleLblTaDesc->ContTa.TextArea));

            Display_Setting_Done(ACT_ID_SETTING_ENTER_SECURITY_CODE,PHONE_TEXT_ID_SECURITY_CODE_CHG,ACT_ID_SETTING_CHANGE_ACCESS_CODE);
        }

        // new code verify fail
        else
        {
            Setting_Set_Access_Code_Change_Status(SETTING_SECURITY_NEW_ENTERING);
            NormalNoTitleLblTaDesc->ContLabel.TxtId = PHONE_TEXT_ID_ENTER_NEW_SECURITY;

            Display_Setting_Error(ACT_ID_SETTING_ENTER_SECURITY_CODE,PHONE_TEXT_ID_CODE_NOT_MATCH,ACT_ID_SETTING_ENTER_SECURITY_CODE,TRUE);
        }
    }

    return(1);
}

/**
 * Callback of Setting_Security_Settings, phone security setting, ON action
 * param (in) Btn: lv_obj_t*
 * param (in) Event: lv_event_t
 * return void:
 */
VOID Display_Setting_Security_PhoneSecurity_Action_On_Cb(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED == Event)
    {
        UI_Normal_Container_List_Desc_t *NormalContainerListDesc = NULL;

        if (FALSE == g_SettingSecuritySettingMng.IsSecurityOn)
        {
            Setting_Set_Security_Status(TRUE);
        }

        NormalContainerListDesc                                                                                 = (UI_Normal_Container_List_Desc_t *)gp_SettingSecuritySettingsCurUIDesc;
        NormalContainerListDesc->ContList.ContainerList[NormalContainerListDesc->ContList.Index].u.Label2.TxtId = PHONE_TEXT_ID_ON;

        Display_Setting_Done(ACT_ID_SETTING_ON_OFF, PHONE_TEXT_ID_DONE,ACT_ID_SETTING_SECURITY_SETTINGS);
    }
}

/**
 * Callback of Setting_Security_Settings, phone security setting, OFF action
 * param (in) Btn: lv_obj_t*
 * param (in) Event: lv_event_t
 * return void:
 */
VOID Display_Setting_Security_PhoneSecurity_Action_Off_Cb(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED == Event)
    {
        UI_Normal_Container_List_Desc_t *NormalContainerListDesc = NULL;

        if (TRUE == g_SettingSecuritySettingMng.IsSecurityOn)
        {
            Setting_Set_Security_Status(FALSE);
        }

        NormalContainerListDesc                                                                                 = (UI_Normal_Container_List_Desc_t *)gp_SettingSecuritySettingsCurUIDesc;
        NormalContainerListDesc->ContList.ContainerList[NormalContainerListDesc->ContList.Index].u.Label2.TxtId = PHONE_TEXT_ID_OFF;

        Display_Setting_Done(ACT_ID_SETTING_ON_OFF, PHONE_TEXT_ID_DONE,ACT_ID_SETTING_SECURITY_SETTINGS);
    }
}

/**
 *
 * Callback of Setting_Enter_Security_Code, KeyCb, OK, action of "PIN code request" setting menu
 * param (in) obj: lv_obj_t*
 *       (in) key_sta: UI_KEY_STATUS
 *       (in) key_val: UI_KEY_VALUE
 * return UINT8: 0--call system handling outside
 *               1--handled inside
 */
UINT8 Display_Setting_Enter_Security_Code_KeyCb_OK_Action_PinCodeRequest(lv_obj_t      *obj,
                                                                         UI_KEY_STATUS key_sta,
                                                                         UI_KEY_VALUE  key_val)
{
    if (0 != g_SettingSecurityPinCodeTaRestCharacters)
    {
        // In case of invalid code length, need give a waring to user here?
        Display_Setting_Error(ACT_ID_SETTING_ENTER_SECURITY_CODE, PHONE_TEXT_ID_LEN_ERROR,ACT_ID_SETTING_ENTER_SECURITY_CODE, FALSE);
    }
    // in case of valid code length
    else
    {
        // in case of PIN/PUK check
        if (SETTING_PIN_OPERATION_PIN1 == g_SettingSecuritySettingMng.PinOperatingType)
        {
            Display_Setting_Enter_Security_Code_KeyCb_OK_Pin_Chk(obj, key_sta, key_val);
        }
        else if (SETTING_PIN_OPERATION_PUK1 == g_SettingSecuritySettingMng.PinOperatingType)
        {
            Display_Setting_Enter_Security_Code_KeyCb_OK_Puk_Chk(obj, key_sta, key_val);
        }

        // in case of entering new PIN code after PUK checking ok
        else if (  (SETTING_PIN_NEW_ENTERING == g_SettingSecuritySettingMng.AccCodeChgStatus)
                || (SETTING_PIN2_NEW_ENTERING == g_SettingSecuritySettingMng.AccCodeChgStatus)
                   // 2019-05-24, PUK checking needs new PIN together, begin
                || (SETTING_PIN_NEW_ENTERING_PUK_CHK ==
                    g_SettingSecuritySettingMng.AccCodeChgStatus)
                || (SETTING_PIN2_NEW_ENTERING_PUK2_CHK ==
                    g_SettingSecuritySettingMng.AccCodeChgStatus)
                   // 2019-05-24, PUK checking needs new PIN together, end
                || (SETTING_PIN_OPERATION_PUK1_PIN_NEW_ENTERING == g_SettingSecuritySettingMng.PinOperatingType))
        {
            Display_Setting_Enter_Security_Code_KeyCb_OK_Enter_New_Pin(obj, key_sta, key_val);
        }
        // in case of verifying new PIN code
        else if (  (SETTING_PIN_NEW_VERIFYING == g_SettingSecuritySettingMng.AccCodeChgStatus)
                || (SETTING_PIN2_NEW_VERIFYING == g_SettingSecuritySettingMng.AccCodeChgStatus)
                   // 2019-05-24, PUK checking needs new PIN together, begin
                || (SETTING_PIN_NEW_VERIFYING_PUK_CHK ==
                    g_SettingSecuritySettingMng.AccCodeChgStatus)
                || (SETTING_PIN2_NEW_VERIFYING_PUK2_CHK ==
                    g_SettingSecuritySettingMng.AccCodeChgStatus)
                   // 2019-05-24, PUK checking needs new PIN together, end
                || (SETTING_PIN_OPERATION_PUK1_PIN_NEW_VERIFYING == g_SettingSecuritySettingMng.PinOperatingType))
        {
            Display_Setting_Enter_Security_Code_KeyCb_OK_Verify_New_Pin(obj, key_sta, key_val);
        }
    }

    return(1);
} /* Display_Setting_Enter_Security_Code_KeyCb_OK_Action_PinCodeRequest */

/**
 *
 * Callback of Setting_Enter_Security_Code, KeyCb, OK, action of security code check
 * param (in) obj: lv_obj_t*
 *       (in) key_sta: UI_KEY_STATUS
 *       (in) key_val: UI_KEY_VALUE
 * return UINT8: 0--call system handling outside
 *               1--handled inside
 */
UINT8 Display_Setting_Enter_Security_Code_KeyCb_OK_Action_SecurityCodeChk(lv_obj_t      *obj,
                                                                          UI_KEY_STATUS key_sta,
                                                                          UI_KEY_VALUE  key_val)
{
    UINT8                             CurSetting;

    UI_Normal_NoTitle_Label_Ta_Desc_t *NormalNoTitleLblTaDesc;

    NormalNoTitleLblTaDesc =
        (UI_Normal_NoTitle_Label_Ta_Desc_t *)gp_SettingSecuritySettingCurUIDesc;

    if ((0 != g_SettingSecurityPinCodeTaRestCharacters)
        && (SETTING_SECURITY_ACTION_EXT_SECURITY_KEYGUARD_CODE_CHK !=
            g_SettingSecuritySettingMng.OperatingAction))
    {
        // In case of invalid code length, need give a waring to user here?
        Display_Setting_Error(ACT_ID_SETTING_ENTER_SECURITY_CODE, PHONE_TEXT_ID_LEN_ERROR,ACT_ID_SETTING_ENTER_SECURITY_CODE, FALSE);
    }
    // in case of valid code length
    else
    {
        // security code checking ok
        if (TRUE == Setting_Verify_Security_code((INT8 *)lv_textarea_get_text(NormalNoTitleLblTaDesc->ContTa.TextArea)))
        {
            // it's a security check request from external module
            if ((SETTING_SECURITY_ACTION_EXT_SECURITY_CODE_CHK ==
                 g_SettingSecuritySettingMng.OperatingAction)
                || (SETTING_SECURITY_ACTION_EXT_SECURITY_KEYGUARD_CODE_CHK ==
                 g_SettingSecuritySettingMng.OperatingAction))
            {
                gp_SettingSecurityChkSecurityCnf(SETTING_OK);
                gp_SettingSecurityChkSecurityCnf = NULL;
                Setting_Set_Operating_Action(SETTING_SECURITY_ACTION_NONE);
            }
            // security check from "phone security" menu
            else if (SETTING_SECURITY_ACTION_PHONE_SECURITY ==
                     g_SettingSecuritySettingMng.OperatingAction)
            {
                if (FALSE == g_SettingSecuritySettingMng.IsSecurityOn)
                {
                    CurSetting = 0;
                }
                else
                {
                    CurSetting = 1;
                }

                Display_Setting_On_Off(ACT_ID_SETTING_ENTER_SECURITY_CODE,PHONE_TEXT_ID_PHONE_SECURITY,CurSetting,Display_Setting_Security_PhoneSecurity_Action_On_Cb,Display_Setting_Security_PhoneSecurity_Action_Off_Cb);
            }
        }
        // security code check fail
        else
        {
            // it's a security check request from external module
            if ((SETTING_SECURITY_ACTION_EXT_SECURITY_CODE_CHK ==
                 g_SettingSecuritySettingMng.OperatingAction)
                || (SETTING_SECURITY_ACTION_EXT_SECURITY_KEYGUARD_CODE_CHK ==
                 g_SettingSecuritySettingMng.OperatingAction))
            {
                NormalNoTitleLblTaDesc->ContLabel.TxtId = PHONE_TEXT_ID_ENTER_SECURITY;
                Display_Setting_Enter_Security_Code_Update_Screen(NormalNoTitleLblTaDesc, 0);

                // gp_SettingSecurityChkSecurityCnf(SETTING_ERROR);
                // gp_SettingSecurityChkSecurityCnf = NULL;
                // Setting_Set_Operating_Action(SETTING_SECURITY_ACTION_NONE);
            }
            // security check from "phone security" menu
            else if (SETTING_SECURITY_ACTION_PHONE_SECURITY ==
                     g_SettingSecuritySettingMng.OperatingAction)
            {
            }
            Display_Setting_Error(ACT_ID_SETTING_ENTER_SECURITY_CODE, PHONE_TEXT_ID_CODE_ERROR,ACT_ID_SETTING_ENTER_SECURITY_CODE, TRUE);
        }
    }

    return(1);
} /* Display_Setting_Enter_Security_Code_KeyCb_OK_Action_SecurityCodeChk */

/**
 *
 * Callback of Setting_Enter_Security_Code, KeyCb, OK, action of "change access code" setting menu
 * param (in) obj: lv_obj_t*
 *       (in) key_sta: UI_KEY_STATUS
 *       (in) key_val: UI_KEY_VALUE
 * return UINT8: 0--call system handling outside
 *               1--handled inside
 */
UINT8 Display_Setting_Enter_Security_Code_KeyCb_OK_Action_ChgAccCode(lv_obj_t      *obj,
                                                                     UI_KEY_STATUS key_sta,
                                                                     UI_KEY_VALUE  key_val)
{
    if (0 != g_SettingSecurityPinCodeTaRestCharacters)
    {
        // In case of invalid code length, need give a waring to user here?
        Display_Setting_Error(ACT_ID_SETTING_ENTER_SECURITY_CODE, PHONE_TEXT_ID_LEN_ERROR,ACT_ID_SETTING_ENTER_SECURITY_CODE, FALSE);
    }
    // in case of valid code length
    else
    {
        // change security code: enter old code
        if (SETTING_SECURITY_OLD_ENTERING == g_SettingSecuritySettingMng.AccCodeChgStatus)
        {
            Display_Setting_Enter_Security_Code_KeyCb_OK_Enter_Old_Security_Code(obj, key_sta,key_val);
        }
        // change security code: enter new code
        else if (SETTING_SECURITY_NEW_ENTERING == g_SettingSecuritySettingMng.AccCodeChgStatus)
        {
            Display_Setting_Enter_Security_Code_KeyCb_OK_Enter_New_Security_Code(obj, key_sta,key_val);
        }
        // change security code: verify new code
        else if (SETTING_SECURITY_NEW_VERIFYING == g_SettingSecuritySettingMng.AccCodeChgStatus)
        {
            Display_Setting_Enter_Security_Code_KeyCb_OK_Verify_New_Security_Code(obj, key_sta,key_val);
        }

        // change PIN/PIN2 code: enter old code
        else if (  (SETTING_PIN_OLD_ENTERING == g_SettingSecuritySettingMng.AccCodeChgStatus)
                || (SETTING_PIN2_OLD_ENTERING == g_SettingSecuritySettingMng.AccCodeChgStatus))
        {
            Display_Setting_Enter_Security_Code_KeyCb_OK_Enter_Old_Pin(obj, key_sta, key_val);
        }
        // change PIN/PIN2 code: enter new code
        else if (  (SETTING_PIN_NEW_ENTERING == g_SettingSecuritySettingMng.AccCodeChgStatus)
                || (SETTING_PIN2_NEW_ENTERING == g_SettingSecuritySettingMng.AccCodeChgStatus)
                   // 2019-05-24, PUK checking needs new PIN together, begin
                || (SETTING_PIN_NEW_ENTERING_PUK_CHK ==
                    g_SettingSecuritySettingMng.AccCodeChgStatus)
                || (SETTING_PIN2_NEW_ENTERING_PUK2_CHK ==
                    g_SettingSecuritySettingMng.AccCodeChgStatus)
                   // 2019-05-24, PUK checking needs new PIN together, end
                   )
        {
            Display_Setting_Enter_Security_Code_KeyCb_OK_Enter_New_Pin(obj, key_sta, key_val);
        }
        // change PIN/PIN2 code: verify new code
        else if (  (SETTING_PIN_NEW_VERIFYING == g_SettingSecuritySettingMng.AccCodeChgStatus)
                || (SETTING_PIN2_NEW_VERIFYING == g_SettingSecuritySettingMng.AccCodeChgStatus)
                   // 2019-05-24, PUK checking needs new PIN together, begin
                || (SETTING_PIN_NEW_VERIFYING_PUK_CHK ==
                    g_SettingSecuritySettingMng.AccCodeChgStatus)
                || (SETTING_PIN2_NEW_VERIFYING_PUK2_CHK ==
                    g_SettingSecuritySettingMng.AccCodeChgStatus)
                   // 2019-05-24, PUK checking needs new PIN together, end
                   )
        {
            Display_Setting_Enter_Security_Code_KeyCb_OK_Verify_New_Pin(obj, key_sta, key_val);
        }

        // in case of PUK check
        else if (SETTING_PUK_ENTERING == g_SettingSecuritySettingMng.AccCodeChgStatus)
        {
            Display_Setting_Enter_Security_Code_KeyCb_OK_Puk_Chk(obj, key_sta, key_val);
        }
        else if (SETTING_PUK2_ENTERING == g_SettingSecuritySettingMng.AccCodeChgStatus)
        {
            Display_Setting_Enter_Security_Code_KeyCb_OK_Puk2_Chk(obj, key_sta, key_val);
        }
    }

    return(1);
} /* Display_Setting_Enter_Security_Code_KeyCb_OK_Action_ChgAccCode */

/**
 *
 * Callback of Setting_Enter_Security_Code, KeyCb, OK, action of external PIN check request
 * param (in) obj: lv_obj_t*
 *       (in) key_sta: UI_KEY_STATUS
 *       (in) key_val: UI_KEY_VALUE
 * return UINT8: 0--call system handling outside
 *               1--handled inside
 */
UINT8 Display_Setting_Enter_Security_Code_KeyCb_OK_Action_ExtPinChk(lv_obj_t      *obj,
                                                                    UI_KEY_STATUS key_sta,
                                                                    UI_KEY_VALUE  key_val)
{
    if (0 != g_SettingSecurityPinCodeTaRestCharacters)
    {
        // In case of invalid code length, need give a waring to user here?
        Display_Setting_Error(ACT_ID_SETTING_ENTER_SECURITY_CODE, PHONE_TEXT_ID_LEN_ERROR,ACT_ID_SETTING_ENTER_SECURITY_CODE, FALSE);
    }
    // in case of valid code length
    else
    {
        // in case of PIN/PUK check
        if (SETTING_PIN_OPERATION_PIN1 == g_SettingSecuritySettingMng.PinOperatingType)
        {
            Display_Setting_Enter_Security_Code_KeyCb_OK_Pin_Chk(obj, key_sta, key_val);
        }
        else if (SETTING_PIN_OPERATION_PUK1 == g_SettingSecuritySettingMng.PinOperatingType)
        {
            Display_Setting_Enter_Security_Code_KeyCb_OK_Puk_Chk(obj, key_sta, key_val);
        }
        else if (SETTING_PIN_OPERATION_PIN2 == g_SettingSecuritySettingMng.PinOperatingType)
        {
            Display_Setting_Enter_Security_Code_KeyCb_OK_Pin2_Chk(obj, key_sta, key_val);
        }
        else if (SETTING_PIN_OPERATION_PUK2 == g_SettingSecuritySettingMng.PinOperatingType)
        {
            Display_Setting_Enter_Security_Code_KeyCb_OK_Puk2_Chk(obj, key_sta, key_val);
        }

        // in case of entering new PIN code after PUK checking ok
        else if (  (SETTING_PIN_NEW_ENTERING == g_SettingSecuritySettingMng.AccCodeChgStatus)
                || (SETTING_PIN2_NEW_ENTERING == g_SettingSecuritySettingMng.AccCodeChgStatus)
                   // 2019-05-24, PUK checking needs new PIN together, begin
                || (SETTING_PIN_NEW_ENTERING_PUK_CHK ==
                    g_SettingSecuritySettingMng.AccCodeChgStatus)
                || (SETTING_PIN2_NEW_ENTERING_PUK2_CHK ==
                    g_SettingSecuritySettingMng.AccCodeChgStatus)
                   // 2019-05-24, PUK checking needs new PIN together, end
                || (SETTING_PIN_OPERATION_PUK1_PIN_NEW_ENTERING == g_SettingSecuritySettingMng.PinOperatingType))
        {
            Display_Setting_Enter_Security_Code_KeyCb_OK_Enter_New_Pin(obj, key_sta, key_val);
        }
        // in case of verifying new PIN code
        else if (  (SETTING_PIN_NEW_VERIFYING == g_SettingSecuritySettingMng.AccCodeChgStatus)
                || (SETTING_PIN2_NEW_VERIFYING == g_SettingSecuritySettingMng.AccCodeChgStatus)
                   // 2019-05-24, PUK checking needs new PIN together, begin
                || (SETTING_PIN_NEW_VERIFYING_PUK_CHK ==
                    g_SettingSecuritySettingMng.AccCodeChgStatus)
                || (SETTING_PIN2_NEW_VERIFYING_PUK2_CHK ==
                    g_SettingSecuritySettingMng.AccCodeChgStatus)
                   // 2019-05-24, PUK checking needs new PIN together, end
                || (SETTING_PIN_OPERATION_PUK1_PIN_NEW_VERIFYING == g_SettingSecuritySettingMng.PinOperatingType))
        {
            Display_Setting_Enter_Security_Code_KeyCb_OK_Verify_New_Pin(obj, key_sta, key_val);
        }
    }

    return(1);
} /* Display_Setting_Enter_Security_Code_KeyCb_OK_Action_ExtPinChk */

/**
 *
 * Callback of Setting_Enter_Security_Code, KeyCb
 * param (in) obj: lv_obj_t*
 *       (in) key_sta: UI_KEY_STATUS
 *       (in) key_val: UI_KEY_VALUE
 * return UINT8: 0--call system handling outside
 *               1--handled inside
 */
UINT8 Display_Setting_Enter_Security_Code_KeyCb(lv_obj_t *obj, UI_KEY_STATUS key_sta,
                                                UI_KEY_VALUE key_val)
{
    INT8                              LabelValue[3] = { 0, 0, 0 };
    UINT8                             MaxTaInputLen;

    UI_Normal_NoTitle_Label_Ta_Desc_t *NormalNoTitleLblTaDesc;
    UI_Normal_List_Only_Desc_t        *NormalLstOnlyDesc;

    NormalNoTitleLblTaDesc =
        (UI_Normal_NoTitle_Label_Ta_Desc_t *)gp_SettingSecuritySettingCurUIDesc;
    MaxTaInputLen = lv_textarea_get_max_length(NormalNoTitleLblTaDesc->ContTa.TextArea);

    if (KEY_RELEASED != key_sta)
    {
        return(0);
    }

    switch (key_val)
    {
    case KEY_OK:
        switch (g_SettingSecuritySettingMng.OperatingAction)
        {
        case SETTING_SECURITY_ACTION_PIN_CODE_REQUEST:
            Display_Setting_Enter_Security_Code_KeyCb_OK_Action_PinCodeRequest(obj, key_sta,key_val);
            break;

        case SETTING_SECURITY_ACTION_PHONE_SECURITY:
        case SETTING_SECURITY_ACTION_EXT_SECURITY_CODE_CHK:
        case SETTING_SECURITY_ACTION_EXT_SECURITY_KEYGUARD_CODE_CHK:
            Display_Setting_Enter_Security_Code_KeyCb_OK_Action_SecurityCodeChk(obj, key_sta,key_val);
            break;

        case SETTING_SECURITY_ACTION_CHG_ACC_CODE:
            Display_Setting_Enter_Security_Code_KeyCb_OK_Action_ChgAccCode(obj, key_sta, key_val);
            break;

        case SETTING_SECURITY_ACTION_EXT_PIN_CHK_NO_CNF:
        case SETTING_SECURITY_ACTION_EXT_PIN_CHK_WITH_CNF:
            Display_Setting_Enter_Security_Code_KeyCb_OK_Action_ExtPinChk(obj, key_sta, key_val);
            break;

        default:
            break;
        }
        return(1);

    case KEY_SOFTRIGHT:
        // SOFTRIGHT key used as CLEAR
        if (g_SettingSecurityPinCodeTaRestCharacters < MaxTaInputLen)
        {
            g_SettingSecurityPinCodeTaRestCharacters++;
            if (g_SettingSecurityPinCodeTaRestCharacters > 9)
            {
                LabelValue[0] = g_SettingSecurityPinCodeTaRestCharacters / 10 + 0x30;
                LabelValue[1] = g_SettingSecurityPinCodeTaRestCharacters % 10 + 0x30;
            }
            else
            {
                LabelValue[0] = g_SettingSecurityPinCodeTaRestCharacters + 0x30;
            }
            lv_label_set_text(NormalNoTitleLblTaDesc->ContLabelTr.Label, LabelValue);

            // When text area is cleared into empty state, and not external PIN/PUK check, right key: CLEAR -> BACK
            if (g_SettingSecurityPinCodeTaRestCharacters == MaxTaInputLen)
            {
                if (  (SETTING_SECURITY_ACTION_EXT_PIN_CHK_NO_CNF == g_SettingSecuritySettingMng.OperatingAction)
                   || (SETTING_SECURITY_ACTION_EXT_PIN_CHK_WITH_CNF == g_SettingSecuritySettingMng.OperatingAction))
                {
                    lv_obj_set_hidden(NormalNoTitleLblTaDesc->ButtonCont.ButtonR.Button, TRUE);
                }
                else
                {
                    NormalNoTitleLblTaDesc->ButtonCont.ButtonR.TxtId = PHONE_TEXT_ID_BACK;
                    lv_label_set_text(lv_obj_get_child(NormalNoTitleLblTaDesc->ButtonCont.ButtonR.Button,NULL),(INT8 *)lv_lang_get_text(NormalNoTitleLblTaDesc->ButtonCont.ButtonR.TxtId));
                }
            }
            return(0);
        }
        // SOFTRIGHT key used as BACK
        else
        {
            // it's a pin check request from external module
            if (SETTING_SECURITY_ACTION_EXT_PIN_CHK_NO_CNF ==
                g_SettingSecuritySettingMng.OperatingAction)
            {
                // Nav_Back(ACT_ID_SETTING_ENTER_SECURITY_CODE);
                // Setting_Set_Operating_Action(SETTING_SECURITY_ACTION_NONE);
            }
            else if (SETTING_SECURITY_ACTION_EXT_PIN_CHK_WITH_CNF ==
                     g_SettingSecuritySettingMng.OperatingAction)
            {
                // gp_SettingSecurityChkPinCnf(g_SettingSecuritySettingMng.OperatingSIM, SETTING_BACK);
                // gp_SettingSecurityChkPinCnf = NULL;
                // Setting_Set_Operating_Action(SETTING_SECURITY_ACTION_NONE);
            }
            else if (SETTING_SECURITY_ACTION_EXT_SECURITY_CODE_CHK ==
                     g_SettingSecuritySettingMng.OperatingAction)
            {
                gp_SettingSecurityChkSecurityCnf(SETTING_BACK);
                gp_SettingSecurityChkSecurityCnf = NULL;
                Nav_Back(ACT_ID_ANY);
                Setting_Set_Operating_Action(SETTING_SECURITY_ACTION_NONE);
            }
            else
            {
                if (SETTING_SECURITY_ACTION_CHG_ACC_CODE ==
                    g_SettingSecuritySettingMng.OperatingAction)
                {
                    NormalLstOnlyDesc = (UI_Normal_List_Only_Desc_t *)gp_SettingChangeAccCodeCurUIDesc;

                    if (1 == NormalLstOnlyDesc->List.Index)
                    {
                        Setting_Set_Access_Code_Change_Status(SETTING_PIN_OLD_ENTERING);
                    }
                    else if (2 == NormalLstOnlyDesc->List.Index)
                    {
                        Setting_Set_Access_Code_Change_Status(SETTING_PIN2_OLD_ENTERING);
                    }
                }

                Nav_Back(ACT_ID_SETTING_ENTER_SECURITY_CODE);
            }

            g_SettingSecurityPinCodeTaRestCharacters = MaxTaInputLen;
            return(1);
        }

    case KEY_0:
    case KEY_1:
    case KEY_2:
    case KEY_3:
    case KEY_4:
    case KEY_5:
    case KEY_6:
    case KEY_7:
    case KEY_8:
    case KEY_9:
        // When text area leaved empty state, right key: BACK -> CLEAR
        if (g_SettingSecurityPinCodeTaRestCharacters == MaxTaInputLen)
        {
            // in external requested pin/puk checking case, enable the CLEAR button
            if (  (SETTING_SECURITY_ACTION_EXT_PIN_CHK_NO_CNF ==
                   g_SettingSecuritySettingMng.OperatingAction)
               || (SETTING_SECURITY_ACTION_EXT_PIN_CHK_WITH_CNF ==
                   g_SettingSecuritySettingMng.OperatingAction))
            {
                lv_obj_set_hidden(NormalNoTitleLblTaDesc->ButtonCont.ButtonR.Button, FALSE);
            }
            lv_label_set_text(lv_obj_get_child(NormalNoTitleLblTaDesc->ButtonCont.ButtonR.Button,NULL),(INT8 *)lv_lang_get_text(PHONE_TEXT_ID_CLEAR));
        }

        if (g_SettingSecurityPinCodeTaRestCharacters > 0)
        {
            g_SettingSecurityPinCodeTaRestCharacters--;
            if (g_SettingSecurityPinCodeTaRestCharacters > 9)
            {
                LabelValue[0] = g_SettingSecurityPinCodeTaRestCharacters / 10 + 0x30;
                LabelValue[1] = g_SettingSecurityPinCodeTaRestCharacters % 10 + 0x30;
            }
            else
            {
                LabelValue[0] = g_SettingSecurityPinCodeTaRestCharacters + 0x30;
            }
            lv_label_set_text(NormalNoTitleLblTaDesc->ContLabelTr.Label, LabelValue);
        }

        return(0);

    case KEY_END:
    {
        // it's a pin check request from external module
        if (SETTING_SECURITY_ACTION_EXT_PIN_CHK_NO_CNF ==
            g_SettingSecuritySettingMng.OperatingAction)
        {
            // Nav_Back(ACT_ID_SETTING_ENTER_SECURITY_CODE);
            // Setting_Set_Operating_Action(SETTING_SECURITY_ACTION_NONE);
        }
        else if (SETTING_SECURITY_ACTION_EXT_PIN_CHK_WITH_CNF ==
                 g_SettingSecuritySettingMng.OperatingAction)
        {
            // gp_SettingSecurityChkPinCnf(g_SettingSecuritySettingMng.OperatingSIM, SETTING_BACK);
            // gp_SettingSecurityChkPinCnf = NULL;
            // Setting_Set_Operating_Action(SETTING_SECURITY_ACTION_NONE);
        }
        else if ((SETTING_SECURITY_ACTION_EXT_SECURITY_CODE_CHK ==
                  g_SettingSecuritySettingMng.OperatingAction)
            || (SETTING_SECURITY_ACTION_EXT_SECURITY_KEYGUARD_CODE_CHK ==
                  g_SettingSecuritySettingMng.OperatingAction))
        {
            gp_SettingSecurityChkSecurityCnf(SETTING_BACK);
            gp_SettingSecurityChkSecurityCnf = NULL;
            Nav_Back(ACT_ID_ANY);
            Setting_Set_Operating_Action(SETTING_SECURITY_ACTION_NONE);
        }
        else
        {
            Nav_Home(ACT_ID_ANY);
        }

        return(1);
    }

    default:
        return(0);
    } /* switch */
}     /* Display_Setting_Enter_Security_Code_KeyCb */

/**
 * display Setting_Enter_Security_Code
 * param (in) CallerActId : ACTIVITY_ID, the activity Id from which entered this screen
 *       (in) TxtId       : UI_PHONE_TEXT_ID, the text shown on screen
 *       (in) NextActId   : ACTIVITY_ID, the next activity Id
 *       (in) TriesLeftEnabled : BOOL, whether to show "x tries left"
 * return void:
 */
VOID Display_Setting_Enter_Security_Code(ACTIVITY_ID      CallerActId,
                                         UI_PHONE_TEXT_ID TxtId,
                                         ACTIVITY_ID      NextActId,
                                         BOOL             TriesLeftEnabled)
{
    UI_Normal_NoTitle_Label_Ta_Desc_t *NormalNoTitleLblTaDesc;
    Nav_Func_List_t                   FuncList;

    NormalNoTitleLblTaDesc =
        (UI_Normal_NoTitle_Label_Ta_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Normal_NoTitle_Label_Ta_Desc_t));
    Hal_Mem_Set(NormalNoTitleLblTaDesc, 0, sizeof(UI_Normal_NoTitle_Label_Ta_Desc_t));

    NormalNoTitleLblTaDesc->ContLabelTl.TxtAlign = LV_LABEL_ALIGN_LEFT;

    // NormalNoTitleLblTaDesc->ContLabelTr.TxtId = ;     //Set in OnCreate() handling
    NormalNoTitleLblTaDesc->ContLabelTr.TxtAlign = LV_LABEL_ALIGN_RIGHT;

    NormalNoTitleLblTaDesc->ContLabel.TxtId    = TxtId;
    NormalNoTitleLblTaDesc->ContLabel.TxtAlign = LV_LABEL_ALIGN_LEFT;

    // NormalNoTitleLblTaDesc->ContTa.TaTxt = Hal_Mem_Alloc(sizeof(4));
    NormalNoTitleLblTaDesc->ContTa.TaCursorHide = FALSE;
    NormalNoTitleLblTaDesc->ContTa.TaAlign      = LV_LABEL_ALIGN_LEFT;

    NormalNoTitleLblTaDesc->ButtonCont.ButtonL.Valid = FALSE;
    NormalNoTitleLblTaDesc->ButtonCont.ButtonM.Valid = TRUE;
    NormalNoTitleLblTaDesc->ButtonCont.ButtonM.TxtId = PHONE_TEXT_ID_OK;
    NormalNoTitleLblTaDesc->ButtonCont.ButtonR.Valid = TRUE;
    NormalNoTitleLblTaDesc->ButtonCont.ButtonR.TxtId = PHONE_TEXT_ID_BACK;

    NormalNoTitleLblTaDesc->KeyFunc = Display_Setting_Enter_Security_Code_KeyCb;

    Hal_Mem_Set(&FuncList, 0, sizeof(Nav_Func_List_t));
    FuncList.OnShow         = UI_Normal_NoTitle_Label_Ta_Create;
    FuncList.OnCreate       = Display_Setting_Enter_Security_Code_Create;
    FuncList.OnRestoreState = Display_Setting_Enter_Security_Code_Create;
    FuncList.OnDestroy      = Display_Setting_Enter_Security_Code_Destroy;

    gp_SettingSecuritySettingCurUIDesc = (VOID *)NormalNoTitleLblTaDesc;
    Setting_Set_Pin_Trying(TriesLeftEnabled);
    g_SettingSecurityCheckCallerActId       = CallerActId;
    g_SettingSecurityAutoNextActIdAfterDone = NextActId;
    Nav_Forward(CallerActId, ACT_ID_SETTING_ENTER_SECURITY_CODE, &FuncList,(VOID *)NormalNoTitleLblTaDesc);
} /* Display_Setting_Enter_Security_Code */

/**
 * to check PIN code
 * param (in) SimId: MMI_MODEM_SIM_ID
 * return  void
 */
VOID Setting_Check_PIN_Req(MMI_MODEM_SIM_ID SimId, Setting_Check_PIN_Cnf_t CheckPinCnf)
{
    MMI_Modem_Pin_Lock_t PinLockQuery;

    gp_SettingSecurityChkPinCnf = CheckPinCnf;
    Setting_Set_Operating_Action(SETTING_SECURITY_ACTION_EXT_PIN_CHK_WITH_CNF);

    if (MMI_MODEM_SIM_1 == SimId)
    {
        // get sim status
        Setting_Set_Operating_Sim_Id(MMI_MODEM_SIM_1);

        PinLockQuery.SimId   = MMI_MODEM_SIM_1;
        PinLockQuery.PinType = MMI_MODEM_PIN1;
        MMI_Modem_Query_Pin_Lock(&PinLockQuery);

        if (PinLockQuery.RetriesLeft > 0)
        {
            Setting_Set_Pin_Operating_Type(SETTING_PIN_OPERATION_PIN1);
        }
        // if PIN blocked, further check PUK status
        else
        {
            PinLockQuery.PinType = MMI_MODEM_PUK;
            MMI_Modem_Query_Pin_Lock(&PinLockQuery);

            // can do PUK check
            if (PinLockQuery.RetriesLeft > 0)
            {
                Setting_Set_Pin_Operating_Type(SETTING_PIN_OPERATION_PUK1);
            }
        }

        Display_Setting_Enter_Security_Code(ACT_ID_ANY, PHONE_TEXT_ID_ENTER_SIM1_PIN, ACT_ID_ANY,TRUE);
    }
    else
    {
        // get sim status
        Setting_Set_Operating_Sim_Id(MMI_MODEM_SIM_2);

        PinLockQuery.SimId   = MMI_MODEM_SIM_2;
        PinLockQuery.PinType = MMI_MODEM_PIN1;
        MMI_Modem_Query_Pin_Lock(&PinLockQuery);

        if (PinLockQuery.RetriesLeft > 0)
        {
            Setting_Set_Pin_Operating_Type(SETTING_PIN_OPERATION_PIN1);
        }
        // if PIN blocked, further check PUK status
        else
        {
            PinLockQuery.PinType = MMI_MODEM_PUK;
            MMI_Modem_Query_Pin_Lock(&PinLockQuery);

            // can do PUK check
            if (PinLockQuery.RetriesLeft > 0)
            {
                Setting_Set_Pin_Operating_Type(SETTING_PIN_OPERATION_PUK1);
            }
        }

        Display_Setting_Enter_Security_Code(ACT_ID_ANY, PHONE_TEXT_ID_ENTER_SIM2_PIN, ACT_ID_ANY,TRUE);
    }
} /* Setting_Check_PIN_Req */

/**
 * to check security key guard code
 * param (in) void
 * return  void
 */
VOID Setting_Check_Security_Keyguard_Req(Setting_Check_Security_Cnf_t CheckSecurityCnf)
{
    if (TRUE == g_SettingPhoneSettingMng.KeyguardOn)
    {
        gp_SettingSecurityChkSecurityCnf = CheckSecurityCnf;
        Setting_Set_Operating_Action(SETTING_SECURITY_ACTION_EXT_SECURITY_KEYGUARD_CODE_CHK);
        Display_Setting_Enter_Security_Code(ACT_ID_ANY,PHONE_TEXT_ID_ENTER_SECURITY,ACT_ID_ANY,FALSE);
    }
    else
    {
        CheckSecurityCnf(SETTING_OK);
    }
}

/**
 * to check Security code
 * param (in) void
 * return  void
 */
VOID Setting_Check_Security_Req(Setting_Check_Security_Cnf_t CheckSecurityCnf)
{
    if (TRUE == g_SettingSecuritySettingMng.IsSecurityOn)
    {
        gp_SettingSecurityChkSecurityCnf = CheckSecurityCnf;
        Setting_Set_Operating_Action(SETTING_SECURITY_ACTION_EXT_SECURITY_CODE_CHK);
        Display_Setting_Enter_Security_Code(ACT_ID_ANY,PHONE_TEXT_ID_ENTER_SECURITY,ACT_ID_ANY,FALSE);
    }
    else
    {
        CheckSecurityCnf(SETTING_OK);
    }
}

/**
 * Callback of Setting_Security_Settings, PIN code request, ON action
 * param (in) Btn: lv_obj_t*
 * param (in) Event: lv_event_t
 * return void:
 */
VOID Display_Setting_Security_PinCodeRequest_Action_On_Cb(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED == Event)
    {
        UI_PHONE_TEXT_ID     TxtId;
        MMI_Modem_Pin_Lock_t PinLockQuery;

        // if the current is OFF & the user sets ON
        if (FALSE == g_SettingSecuritySettingMng.IsPinRequest[g_SettingSecuritySettingMng.OperatingSIM])
        {
            PinLockQuery.SimId   = g_SettingSecuritySettingMng.OperatingSIM;
            PinLockQuery.PinType = MMI_MODEM_PIN1;
            MMI_Modem_Query_Pin_Lock(&PinLockQuery);

            // can do PIN check
            if (PinLockQuery.RetriesLeft > 0)
            {
                if (MMI_MODEM_SIM_1 == g_SettingSecuritySettingMng.OperatingSIM)
                {
                    TxtId = PHONE_TEXT_ID_ENTER_SIM1_PIN;
                }
                else
                {
                    TxtId = PHONE_TEXT_ID_ENTER_SIM2_PIN;
                }
                Setting_Set_Pin_Operating_Type(SETTING_PIN_OPERATION_PIN1);
            }
            // if PIN blocked, further check PUK status
            else
            {
                PinLockQuery.PinType = MMI_MODEM_PUK;
                MMI_Modem_Query_Pin_Lock(&PinLockQuery);

                // can do PUK check
                if (PinLockQuery.RetriesLeft > 0)
                {
                    if (MMI_MODEM_SIM_1 == g_SettingSecuritySettingMng.OperatingSIM)
                    {
                        TxtId = PHONE_TEXT_ID_ENTER_SIM1_PUK;
                    }
                    else
                    {
                        TxtId = PHONE_TEXT_ID_ENTER_SIM2_PUK;
                    }
                    Setting_Set_Pin_Operating_Type(SETTING_PIN_OPERATION_PUK1);
                }
                // if PUK blocked
                else
                {
                    if (MMI_MODEM_SIM_1 == g_SettingSecuritySettingMng.OperatingSIM)
                    {
                        Display_Setting_Security_Puk_Blocked(ACT_ID_SETTING_ON_OFF,PHONE_TEXT_ID_SIM1PUK_BLOCKED,ACT_ID_SETTING_SIM_SELECTION);
                    }
                    else
                    {
                        Display_Setting_Security_Puk_Blocked(ACT_ID_SETTING_ON_OFF,PHONE_TEXT_ID_SIM2PUK_BLOCKED,ACT_ID_SETTING_SIM_SELECTION);
                    }
                }
            }

            // Not PUK blocked
            if (PinLockQuery.RetriesLeft > 0)
            {
                Display_Setting_Enter_Security_Code(ACT_ID_SETTING_ON_OFF,TxtId,ACT_ID_SETTING_SIM_SELECTION,TRUE);
            }
        }
        // PIN request status no change
        else
        {
            Display_Setting_Done(ACT_ID_SETTING_ON_OFF, PHONE_TEXT_ID_DONE,ACT_ID_SETTING_SIM_SELECTION);
        }
    }
} /* Display_Setting_Security_PinCodeRequest_Action_On_Cb */

/**
 * Callback of Setting_Security_Settings, PIN code request, OFF action
 * param (in) Btn: lv_obj_t*
 * param (in) Event: lv_event_t
 * return void:
 */
VOID Display_Setting_Security_PinCodeRequest_Action_Off_Cb(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED == Event)
    {
        UI_PHONE_TEXT_ID     TxtId;
        MMI_Modem_Pin_Lock_t PinLockQuery;

        // if the current is ON & the user sets OFF
        if (TRUE == g_SettingSecuritySettingMng.IsPinRequest[g_SettingSecuritySettingMng.OperatingSIM])
        {
            PinLockQuery.SimId   = g_SettingSecuritySettingMng.OperatingSIM;
            PinLockQuery.PinType = MMI_MODEM_PIN1;
            MMI_Modem_Query_Pin_Lock(&PinLockQuery);

            // can do PIN check
            if (PinLockQuery.RetriesLeft > 0)
            {
                if (MMI_MODEM_SIM_1 == g_SettingSecuritySettingMng.OperatingSIM)
                {
                    TxtId = PHONE_TEXT_ID_ENTER_SIM1_PIN;
                }
                else
                {
                    TxtId = PHONE_TEXT_ID_ENTER_SIM2_PIN;
                }
                Setting_Set_Pin_Operating_Type(SETTING_PIN_OPERATION_PIN1);
            }
            // if PIN blocked, further check PUK status
            else
            {
                PinLockQuery.PinType = MMI_MODEM_PUK;
                MMI_Modem_Query_Pin_Lock(&PinLockQuery);

                // can do PUK check
                if (PinLockQuery.RetriesLeft > 0)
                {
                    if (MMI_MODEM_SIM_1 == g_SettingSecuritySettingMng.OperatingSIM)
                    {
                        TxtId = PHONE_TEXT_ID_ENTER_SIM1_PUK;
                    }
                    else
                    {
                        TxtId = PHONE_TEXT_ID_ENTER_SIM2_PUK;
                    }
                    Setting_Set_Pin_Operating_Type(SETTING_PIN_OPERATION_PUK1);
                }
                // if PUK blocked
                else
                {
                    if (MMI_MODEM_SIM_1 == g_SettingSecuritySettingMng.OperatingSIM)
                    {
                        Display_Setting_Security_Puk_Blocked(ACT_ID_SETTING_ON_OFF,PHONE_TEXT_ID_SIM1PUK_BLOCKED,ACT_ID_SETTING_SIM_SELECTION);
                    }
                    else
                    {
                        Display_Setting_Security_Puk_Blocked(ACT_ID_SETTING_ON_OFF,PHONE_TEXT_ID_SIM2PUK_BLOCKED,ACT_ID_SETTING_SIM_SELECTION);
                    }
                }
            }

            // Not PUK blocked
            if (PinLockQuery.RetriesLeft > 0)
            {
                Display_Setting_Enter_Security_Code(ACT_ID_SETTING_ON_OFF,TxtId,ACT_ID_SETTING_SIM_SELECTION,TRUE);
            }
        }
        // PIN request status no change
        else
        {
            Display_Setting_Done(ACT_ID_SETTING_ON_OFF, PHONE_TEXT_ID_DONE,ACT_ID_SETTING_SIM_SELECTION);
        }
    }
} /* Display_Setting_Security_PinCodeRequest_Action_Off_Cb */

/**
 * Callback of Setting_Security_Settings, PIN code request, SIM1 or SIM2 selected
 * param (in) Btn: lv_obj_t*
 * return lv_res_t: always return LV_RES_OK
 */
VOID Display_Setting_Security_PinCodeRequest_Sim_Selection_Cb(MMI_MODEM_SIM_ID SimId)
{
    UINT8 CurSetting;

    Setting_Set_Operating_Sim_Id(SimId);
    if (FALSE == g_SettingSecuritySettingMng.IsPinRequest[SimId])
    {
        CurSetting = 0;
    }
    else
    {
        CurSetting = 1;
    }

    Display_Setting_On_Off(ACT_ID_SETTING_SIM_SELECTION,PHONE_TEXT_ID_PIN_CODE_REQ,CurSetting,Display_Setting_Security_PinCodeRequest_Action_On_Cb,Display_Setting_Security_PinCodeRequest_Action_Off_Cb);
}

/**
 * Callback of Setting_Security_Settings, PIN code request
 * param (in) Btn: lv_obj_t*
 * param (in) Event: lv_event_t
 * return void:
 */
VOID Display_Setting_Security_PinCodeRequest_Cb(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED == Event)
    {        
        UI_PHONE_TEXT_ID Sim1ValueTxtId;
        UI_PHONE_TEXT_ID Sim2ValueTxtId;

        Setting_Set_Operating_Action(SETTING_SECURITY_ACTION_PIN_CODE_REQUEST);
        Setting_Set_Access_Code_Change_Status(SETTING_ACC_CODE_CHG_OFF);

        // SIM1 present
        if (TRUE == g_SettingSimStatus[MMI_MODEM_SIM_1])
        {
            if (FALSE == g_SettingSecuritySettingMng.IsPinRequest[0])
            {
                Sim1ValueTxtId = PHONE_TEXT_ID_OFF;
            }
            else
            {
                Sim1ValueTxtId = PHONE_TEXT_ID_ON;
            }
        }
        else
        {
            Sim1ValueTxtId = LV_LANG_TXT_ID_NONE;
        }

        // Query SIM2 pin request status
        if (TRUE == g_SettingSimStatus[MMI_MODEM_SIM_2])
        {
            if (FALSE == g_SettingSecuritySettingMng.IsPinRequest[1])
            {
                Sim2ValueTxtId = PHONE_TEXT_ID_OFF;
            }
            else
            {
                Sim2ValueTxtId = PHONE_TEXT_ID_ON;
            }
        }
        else
        {
            Sim2ValueTxtId = LV_LANG_TXT_ID_NONE;
        }

        Display_Setting_SIM_Selection(ACT_ID_SETTING_SECURITY_SETTINGS,Sim1ValueTxtId,Sim2ValueTxtId,NULL,NULL,Display_Setting_Security_PinCodeRequest_Sim_Selection_Cb);
    }
} /* Display_Setting_Security_PinCodeRequest_Cb */

/**
 * Callback of Setting_Security_Settings, phone security
 * param (in) Btn: lv_obj_t*
 * param (in) Event: lv_event_t
 * return void:
 */
VOID Display_Setting_Security_PhoneSecurity_Cb(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED == Event)
    {
        Setting_Set_Operating_Action(SETTING_SECURITY_ACTION_PHONE_SECURITY);
        Setting_Set_Pin_Operating_Type(SETTING_PIN_OPERATION_OFF);
        Setting_Set_Access_Code_Change_Status(SETTING_ACC_CODE_CHG_OFF);

        Display_Setting_Enter_Security_Code(ACT_ID_SETTING_SECURITY_SETTINGS,PHONE_TEXT_ID_ENTER_SECURITY,ACT_ID_SETTING_SECURITY_SETTINGS,FALSE);
    }
}

/**
 * Callback of Setting_Change_Access_Code, change security code
 * param (in) Btn: lv_obj_t*
 * param (in) Event: lv_event_t
 * return void:
 */
VOID Display_Setting_Change_Access_Code_Security_Cb(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED == Event)
    {
        UI_Normal_List_Only_Desc_t *NormalLstOnlyDesc;

        NormalLstOnlyDesc =
            (UI_Normal_List_Only_Desc_t *)gp_SettingChangeAccCodeCurUIDesc;
        NormalLstOnlyDesc->List.Index = 0;

        Setting_Set_Access_Code_Change_Status(SETTING_SECURITY_OLD_ENTERING);

        Display_Setting_Enter_Security_Code(ACT_ID_SETTING_CHANGE_ACCESS_CODE, PHONE_TEXT_ID_ENTER_OLD_SECURITY,ACT_ID_SETTING_ENTER_SECURITY_CODE,FALSE);
    }
}

/**
 * Callback of Setting_Security_Settings, Change access code, PIN, SIM1 or SIM2 selected
 * param (in) Btn: lv_obj_t*
 * return lv_res_t: always return LV_RES_OK
 */
VOID Display_Setting_Security_ChangeAccessCode_Pin_Sim_Selection_Cb(MMI_MODEM_SIM_ID SimId)
{
    UI_PHONE_TEXT_ID     TxtId;
    MMI_Modem_Pin_Lock_t PinLockQuery;

    Setting_Set_Operating_Sim_Id(SimId);

    // check if PIN/PUK is blocked
    if (SETTING_PIN_OLD_ENTERING == g_SettingSecuritySettingMng.AccCodeChgStatus)
    {
        PinLockQuery.SimId   = SimId;
        PinLockQuery.PinType = MMI_MODEM_PIN1;
        MMI_Modem_Query_Pin_Lock(&PinLockQuery);

        // check PIN enable of disable
        if (FALSE == PinLockQuery.PinEnable)
        {
            Display_Setting_Error(ACT_ID_SETTING_SIM_SELECTION, PHONE_TEXT_ID_SET_PIN_REQUEST_ON, ACT_ID_SETTING_SIM_SELECTION, TRUE);
            return;
        }

        // can do PIN check
        if (PinLockQuery.RetriesLeft > 0)
        {
            if (MMI_MODEM_SIM_1 == SimId)
            {
                TxtId = PHONE_TEXT_ID_ENTER_SIM1_PIN;
            }
            else
            {
                TxtId = PHONE_TEXT_ID_ENTER_SIM2_PIN;
            }
            Display_Setting_Enter_Security_Code(ACT_ID_SETTING_SIM_SELECTION,TxtId,ACT_ID_SETTING_SIM_SELECTION,TRUE);
        }
        // if PIN blocked, further check PUK status
        else
        {
            PinLockQuery.PinType = MMI_MODEM_PUK;
            MMI_Modem_Query_Pin_Lock(&PinLockQuery);

            // can do PUK check
            if (PinLockQuery.RetriesLeft > 0)
            {
                if (MMI_MODEM_SIM_1 == SimId)
                {
                    TxtId = PHONE_TEXT_ID_ENTER_SIM1_PUK;
                }
                else
                {
                    TxtId = PHONE_TEXT_ID_ENTER_SIM2_PUK;
                }
                Setting_Set_Access_Code_Change_Status(SETTING_PUK_ENTERING);
                Display_Setting_Enter_Security_Code(ACT_ID_SETTING_SIM_SELECTION,TxtId,ACT_ID_SETTING_SIM_SELECTION,TRUE);
            }
            // if PUK blocked
            else
            {
                if (MMI_MODEM_SIM_1 == SimId)
                {
                    TxtId = PHONE_TEXT_ID_SIM1PUK_BLOCKED;
                }
                else
                {
                    TxtId = PHONE_TEXT_ID_SIM2PUK_BLOCKED;
                }
                Display_Setting_Security_Puk_Blocked(ACT_ID_SETTING_SIM_SELECTION,TxtId,ACT_ID_SETTING_SIM_SELECTION);
            }
        }
    }

    // check if PIN2/PUK2 is blocked
    else if (SETTING_PIN2_OLD_ENTERING == g_SettingSecuritySettingMng.AccCodeChgStatus)
    {
        PinLockQuery.SimId   = SimId;
        PinLockQuery.PinType = MMI_MODEM_PIN2;
        MMI_Modem_Query_Pin_Lock(&PinLockQuery);

        // can do PIN2 check
        if (PinLockQuery.RetriesLeft > 0)
        {
            if (MMI_MODEM_SIM_1 == SimId)
            {
                TxtId = PHONE_TEXT_ID_ENTER_SIM1_PIN2;
            }
            else
            {
                TxtId = PHONE_TEXT_ID_ENTER_SIM2_PIN2;
            }
            Display_Setting_Enter_Security_Code(ACT_ID_SETTING_SIM_SELECTION,TxtId,ACT_ID_SETTING_SIM_SELECTION,TRUE);
        }
        // if PIN2 blocked, further check PUK2 status
        else
        {
            PinLockQuery.PinType = MMI_MODEM_PUK2;
            MMI_Modem_Query_Pin_Lock(&PinLockQuery);

            // can do PUK2 check
            if (PinLockQuery.RetriesLeft > 0)
            {
                if (MMI_MODEM_SIM_1 == SimId)
                {
                    TxtId = PHONE_TEXT_ID_ENTER_SIM1_PUK2;
                }
                else
                {
                    TxtId = PHONE_TEXT_ID_ENTER_SIM2_PUK2;
                }
                Setting_Set_Access_Code_Change_Status(SETTING_PUK2_ENTERING);
                Display_Setting_Enter_Security_Code(ACT_ID_SETTING_SIM_SELECTION,TxtId,ACT_ID_SETTING_SIM_SELECTION,TRUE);
            }
            // if PUK2 blocked
            else
            {
                if (MMI_MODEM_SIM_1 == SimId)
                {
                    TxtId = PHONE_TEXT_ID_SIM1PUK2_BLOCKED;
                }
                else
                {
                    TxtId = PHONE_TEXT_ID_SIM2PUK2_BLOCKED;
                }
                Display_Setting_Security_Puk_Blocked(ACT_ID_SETTING_SIM_SELECTION,TxtId,ACT_ID_SETTING_SIM_SELECTION);
            }
        }
    }
} /* Display_Setting_Security_ChangeAccessCode_Pin_Sim_Selection_Cb */

/**
 * Callback of Setting_Change_Access_Code, change PIN code
 * param (in) Btn: lv_obj_t*
 * param (in) Event: lv_event_t
 * return void:
 */
VOID Display_Setting_Change_Access_Code_Pin_Cb(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED == Event)
    {
        UI_Normal_List_Only_Desc_t *NormalLstOnlyDesc;

        NormalLstOnlyDesc =
            (UI_Normal_List_Only_Desc_t *)gp_SettingChangeAccCodeCurUIDesc;
        NormalLstOnlyDesc->List.Index = 1;

        Setting_Set_Access_Code_Change_Status(SETTING_PIN_OLD_ENTERING);

        Display_Setting_SIM_Selection(ACT_ID_SETTING_CHANGE_ACCESS_CODE,LV_LANG_TXT_ID_NONE,LV_LANG_TXT_ID_NONE,NULL,NULL,Display_Setting_Security_ChangeAccessCode_Pin_Sim_Selection_Cb);
    }
}

/**
 * Callback of Setting_Change_Access_Code, change PIN2 code
 * param (in) Btn: lv_obj_t*
 * param (in) Event: lv_event_t
 * return void:
 */
VOID Display_Setting_Change_Access_Code_Pin2_Cb(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED == Event)
    {
        UI_Normal_List_Only_Desc_t *NormalLstOnlyDesc;

        NormalLstOnlyDesc =
            (UI_Normal_List_Only_Desc_t *)gp_SettingChangeAccCodeCurUIDesc;
        NormalLstOnlyDesc->List.Index = 2;

        Setting_Set_Access_Code_Change_Status(SETTING_PIN2_OLD_ENTERING);

        Display_Setting_SIM_Selection(ACT_ID_SETTING_CHANGE_ACCESS_CODE,LV_LANG_TXT_ID_NONE,LV_LANG_TXT_ID_NONE,NULL,NULL,Display_Setting_Security_ChangeAccessCode_Pin_Sim_Selection_Cb);
    }
}

/**
 *
 * Callback of Setting_Security_Settings, change access code, on destroy
 * param (in) NormalLstOnlyDesc: UI_Normal_List_Only_Desc_t*
 * return void:
 */
VOID Display_Setting_Change_Access_Code_Destroy(VOID *pPara)
{
    UI_Normal_List_Only_Desc_t *NormalLstOnlyDesc = NULL;

    NormalLstOnlyDesc = (UI_Normal_List_Only_Desc_t *)pPara;

    Hal_Mem_Free(NormalLstOnlyDesc->List.ButtonList);
    Hal_Mem_Free(NormalLstOnlyDesc);
}

/**
 *
 * Callback of Setting_Security_Settings, change access code, KeyCb
 * param (in) obj: lv_obj_t*
 *       (in) key_sta: UI_KEY_STATUS
 *       (in) key_val: UI_KEY_VALUE
 * return UINT8: 0--call system handling outside
 *               1--handled inside
 */
UINT8 Display_Setting_Change_Access_Code_KeyCb(lv_obj_t *obj, UI_KEY_STATUS key_sta,
                                               UI_KEY_VALUE key_val)
{
    if (KEY_RELEASED != key_sta)
    {
        return(0);
    }

    if (KEY_SOFTRIGHT == key_val)
    {
        Nav_Back(ACT_ID_SETTING_CHANGE_ACCESS_CODE);
        return(1);
    }
    else
    {
        return(0);
    }
}

/**
 * display Setting_Change_Access_Code
 * param (in) void:
 * return void:
 */
VOID Display_Setting_Change_Access_Code(VOID)
{
    //
    UI_Normal_List_Only_Desc_t *NormalLstOnlyDesc;
    Nav_Func_List_t            FuncList;

    NormalLstOnlyDesc =
        (UI_Normal_List_Only_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Normal_List_Only_Desc_t));
    Hal_Mem_Set(NormalLstOnlyDesc, 0, sizeof(UI_Normal_List_Only_Desc_t));

    NormalLstOnlyDesc->TitleBar.TxtId      = PHONE_TEXT_ID_CHG_ACCESS_CODE;
    NormalLstOnlyDesc->TitleBar.TxtAlign   = LV_LABEL_ALIGN_CENTER;
    NormalLstOnlyDesc->TitleBar.LabelAlign = LV_ALIGN_IN_TOP_LEFT;

    if ((FALSE == g_SettingSimStatus[MMI_MODEM_SIM_1]) && (FALSE == g_SettingSimStatus[MMI_MODEM_SIM_2]))
    {
        NormalLstOnlyDesc->List.ListButtonCnt = 1;
    }
    else
    {
        NormalLstOnlyDesc->List.ListButtonCnt = 3;
    }

    NormalLstOnlyDesc->List.ButtonList =
        (UI_Button_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Button_Desc_t) * NormalLstOnlyDesc->List.ListButtonCnt);
    Hal_Mem_Set(NormalLstOnlyDesc->List.ButtonList, 0,sizeof(UI_Button_Desc_t) * NormalLstOnlyDesc->List.ListButtonCnt);
    NormalLstOnlyDesc->List.ButtonList[0].Valid       = TRUE;
    NormalLstOnlyDesc->List.ButtonList[0].ButtonIndex = 0;
    NormalLstOnlyDesc->List.ButtonList[0].TxtId       = PHONE_TEXT_ID_CHG_SECURITY_CODE;
    NormalLstOnlyDesc->List.ButtonList[0].ReleaseFun  =
        Display_Setting_Change_Access_Code_Security_Cb;

    if ((TRUE == g_SettingSimStatus[MMI_MODEM_SIM_1]) || (TRUE == g_SettingSimStatus[MMI_MODEM_SIM_2]))
    {
        NormalLstOnlyDesc->List.ButtonList[1].Valid       = TRUE;
        NormalLstOnlyDesc->List.ButtonList[1].ButtonIndex = 1;
        NormalLstOnlyDesc->List.ButtonList[1].TxtId       = PHONE_TEXT_ID_CHG_PIN;
        NormalLstOnlyDesc->List.ButtonList[1].ReleaseFun  = Display_Setting_Change_Access_Code_Pin_Cb;
        NormalLstOnlyDesc->List.ButtonList[2].Valid       = TRUE;
        NormalLstOnlyDesc->List.ButtonList[2].ButtonIndex = 2;
        NormalLstOnlyDesc->List.ButtonList[2].TxtId       = PHONE_TEXT_ID_CHG_PIN2;
        NormalLstOnlyDesc->List.ButtonList[2].ReleaseFun  = Display_Setting_Change_Access_Code_Pin2_Cb;
    }

    NormalLstOnlyDesc->BtnBar.ButtonL.Valid = FALSE;
    NormalLstOnlyDesc->BtnBar.ButtonM.Valid = TRUE;
    NormalLstOnlyDesc->BtnBar.ButtonM.TxtId = PHONE_TEXT_ID_SELECT;
    NormalLstOnlyDesc->BtnBar.ButtonR.Valid = TRUE;
    NormalLstOnlyDesc->BtnBar.ButtonR.TxtId = PHONE_TEXT_ID_BACK;

    NormalLstOnlyDesc->KeyFunc = Display_Setting_Change_Access_Code_KeyCb;

    Hal_Mem_Set(&FuncList, 0, sizeof(Nav_Func_List_t));
    FuncList.OnShow    = UI_Normal_List_Only_Create;
    FuncList.OnDestroy = Display_Setting_Change_Access_Code_Destroy;

    gp_SettingChangeAccCodeCurUIDesc = (VOID *)NormalLstOnlyDesc;
    Nav_Forward(ACT_ID_SETTING_SECURITY_SETTINGS, ACT_ID_SETTING_CHANGE_ACCESS_CODE, &FuncList,(VOID *)NormalLstOnlyDesc);
} /* Display_Setting_Change_Access_Code */

/**
 * Callback of Setting_Security_Settings, change acc codes
 * param (in) Btn: lv_obj_t*
 * param (in) Event: lv_event_t
 * return void:
 */
VOID Display_Setting_Security_ChgAccCode_Cb(lv_obj_t *Btn, lv_event_t Event)
{
    if (LV_EVENT_CLICKED == Event)
    {
        Setting_Set_Operating_Action(SETTING_SECURITY_ACTION_CHG_ACC_CODE);
        Setting_Set_Pin_Operating_Type(SETTING_PIN_OPERATION_OFF);

        Display_Setting_Change_Access_Code();
    }
}

/**
 *
 * Callback of Setting_Security_Settings, on destroy
 * param (in) NormalLstOnlyDesc: UI_Normal_List_Only_Desc_t*
 * return void:
 */
VOID Display_Setting_Security_Settings_Destroy(VOID *pPara)
{
    UI_Normal_Container_List_Desc_t *NormalContainerListDesc = NULL;

    NormalContainerListDesc = (UI_Normal_Container_List_Desc_t *)pPara;

    Hal_Mem_Free(NormalContainerListDesc->ContList.ContainerList);
    Hal_Mem_Free(NormalContainerListDesc);
}

/**
 *
 * Callback of Setting_Security_Settings, KeyCb
 * param (in) obj: lv_obj_t*
 *       (in) key_sta: UI_KEY_STATUS
 *       (in) key_val: UI_KEY_VALUE
 * return UINT8: 0--call system handling outside
 *               1--handled inside
 */
UINT8 Display_Setting_Security_Settings_KeyCb(lv_obj_t *obj, UI_KEY_STATUS key_sta,
                                              UI_KEY_VALUE key_val)
{
    UINT8                           Index                    = 0;
    UI_Normal_Container_List_Desc_t *NormalContainerListDesc = NULL;

    if (KEY_RELEASED != key_sta)
    {
        return(0);
    }

    NormalContainerListDesc = (UI_Normal_Container_List_Desc_t *)gp_SettingSecuritySettingsCurUIDesc;
    Index                   = NormalContainerListDesc->ContList.Index;

    if (KEY_DOWN == key_val)
    {
        Index++;
        Index                                  %= NormalContainerListDesc->ContList.ListContainerCnt;
        NormalContainerListDesc->ContList.Index = Index;
        return(0);
    }
    else if (KEY_UP == key_val)
    {
        Index += NormalContainerListDesc->ContList.ListContainerCnt;
        Index--;
        Index                                  %= NormalContainerListDesc->ContList.ListContainerCnt;
        NormalContainerListDesc->ContList.Index = Index;
        return(0);
    }
    else if (KEY_SOFTRIGHT == key_val)
    {
        Nav_Back(ACT_ID_SETTING_SECURITY_SETTINGS);
        return(1);
    }
    else if (KEY_END == key_val)
    {
        Nav_Home(ACT_ID_ANY);
        return(1);
    }
    else
    {
        return(0);
    }
} /* Display_Setting_Security_Settings_KeyCb */

/**
 * display Setting_Security_Settings
 * param (in) void:
 * return void:
 */
VOID Display_Setting_Security_Settings()
{
    UI_Normal_Container_List_Desc_t *NormalContainerListDesc = NULL;
    Nav_Func_List_t                 FuncList;
    UINT8                           i = 0;

    NormalContainerListDesc =
        (UI_Normal_Container_List_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Normal_Container_List_Desc_t));
    Hal_Mem_Set(NormalContainerListDesc, 0, sizeof(UI_Normal_Container_List_Desc_t));

    NormalContainerListDesc->TitleBar.TxtId      = PHONE_TEXT_ID_SECURITY_SETTINGS;
    NormalContainerListDesc->TitleBar.TxtAlign   = LV_LABEL_ALIGN_CENTER;
    NormalContainerListDesc->TitleBar.LabelAlign = LV_ALIGN_IN_TOP_LEFT;

    NormalContainerListDesc->ContList.Index = 0;

    if ((FALSE == g_SettingSimStatus[MMI_MODEM_SIM_1]) && (FALSE == g_SettingSimStatus[MMI_MODEM_SIM_2]))
    {
        NormalContainerListDesc->ContList.ListContainerCnt = 2;
        NormalContainerListDesc->ContList.ContainerList    =
            (UI_Container_Base_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Container_Base_Desc_t) * NormalContainerListDesc->ContList.ListContainerCnt);
        Hal_Mem_Set(NormalContainerListDesc->ContList.ContainerList, 0,sizeof(UI_Container_Base_Desc_t) * NormalContainerListDesc->ContList.ListContainerCnt);
    }
    else
    {
        NormalContainerListDesc->ContList.ListContainerCnt = 3;
        NormalContainerListDesc->ContList.ContainerList    =
            (UI_Container_Base_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Container_Base_Desc_t) * NormalContainerListDesc->ContList.ListContainerCnt);
        Hal_Mem_Set(NormalContainerListDesc->ContList.ContainerList, 0,sizeof(UI_Container_Base_Desc_t) * NormalContainerListDesc->ContList.ListContainerCnt);

        NormalContainerListDesc->ContList.ContainerList[i].Valid            = TRUE;
        NormalContainerListDesc->ContList.ContainerList[i].Label.TxtId      = PHONE_TEXT_ID_PIN_CODE_REQ;
        NormalContainerListDesc->ContList.ContainerList[i].Label.TxtAlign   = LV_LABEL_ALIGN_LEFT;
        NormalContainerListDesc->ContList.ContainerList[i].Label.LabelAlign = LV_ALIGN_IN_TOP_LEFT;
        NormalContainerListDesc->ContList.ContainerList[i].Choise           = UI_BASE_OBJ_NULL;
        NormalContainerListDesc->ContList.ContainerList[i++].ReleaseFunc    = Display_Setting_Security_PinCodeRequest_Cb;
    }

    NormalContainerListDesc->ContList.ContainerList[i].Valid            = TRUE;
    NormalContainerListDesc->ContList.ContainerList[i].Label.TxtId      = PHONE_TEXT_ID_PHONE_SECURITY;
    NormalContainerListDesc->ContList.ContainerList[i].Label.TxtAlign   = LV_LABEL_ALIGN_LEFT;
    NormalContainerListDesc->ContList.ContainerList[i].Label.LabelAlign = LV_ALIGN_IN_TOP_LEFT;
    NormalContainerListDesc->ContList.ContainerList[i].Choise           = UI_BASE_OBJ_LABEL;
    if (TRUE == g_SettingSecuritySettingMng.IsSecurityOn)
    {
        NormalContainerListDesc->ContList.ContainerList[i].u.Label2.TxtId = PHONE_TEXT_ID_ON;
    }
    else
    {
        NormalContainerListDesc->ContList.ContainerList[i].u.Label2.TxtId = PHONE_TEXT_ID_OFF;
    }
    NormalContainerListDesc->ContList.ContainerList[i].u.Label2.TxtAlign   = LV_LABEL_ALIGN_RIGHT;
    NormalContainerListDesc->ContList.ContainerList[i].u.Label2.LabelAlign = LV_ALIGN_IN_BOTTOM_LEFT;
    NormalContainerListDesc->ContList.ContainerList[i++].ReleaseFunc       = Display_Setting_Security_PhoneSecurity_Cb;

    NormalContainerListDesc->ContList.ContainerList[i].Valid            = TRUE;
    NormalContainerListDesc->ContList.ContainerList[i].Label.TxtId      = PHONE_TEXT_ID_CHG_ACCESS_CODE;
    NormalContainerListDesc->ContList.ContainerList[i].Label.TxtAlign   = LV_LABEL_ALIGN_LEFT;
    NormalContainerListDesc->ContList.ContainerList[i].Label.LabelAlign = LV_ALIGN_IN_TOP_LEFT;
    NormalContainerListDesc->ContList.ContainerList[i].Choise           = UI_BASE_OBJ_NULL;
    NormalContainerListDesc->ContList.ContainerList[i].ReleaseFunc      = Display_Setting_Security_ChgAccCode_Cb;

    NormalContainerListDesc->ButtonBar.ButtonL.Valid = FALSE;
    NormalContainerListDesc->ButtonBar.ButtonM.Valid = TRUE;
    NormalContainerListDesc->ButtonBar.ButtonM.TxtId = PHONE_TEXT_ID_SELECT;
    NormalContainerListDesc->ButtonBar.ButtonR.Valid = TRUE;
    NormalContainerListDesc->ButtonBar.ButtonR.TxtId = PHONE_TEXT_ID_BACK;

    NormalContainerListDesc->KeyFunc = Display_Setting_Security_Settings_KeyCb;

    Hal_Mem_Set(&FuncList, 0, sizeof(Nav_Func_List_t));
    FuncList.OnShow = UI_Normal_Container_List_Create;
    // FuncList.OnCreate  = Display_Setting_Security_Settings_Create;
    FuncList.OnDestroy = Display_Setting_Security_Settings_Destroy;

    gp_SettingSecuritySettingsCurUIDesc = (VOID *)NormalContainerListDesc;
    Nav_Forward(ACT_ID_SETTING, ACT_ID_SETTING_SECURITY_SETTINGS, &FuncList,(VOID *)NormalContainerListDesc);
} /* Display_Setting_Security_Settings */

VOID Display_Setting_Security_Settings_Cb(lv_obj_t *Btn, lv_event_t Event)
{
    if(LV_EVENT_CLICKED == Event)
    {
        Display_Setting_Security_Settings();
    }
}

/**
 * indicate that PIN status changed
 * param (in) simId      :  MMI_MODEM_SIM_ID
 *       (in) PinReqType :  MMI_MODEM_PIN_STATUS_TYPE
 * return  void
 */
VOID  Phone_Modem_Pin_Status_Change_Ind(MMI_MODEM_SIM_ID SimId, MMI_MODEM_PIN_STATUS_TYPE PinReqType)
{
    ACTIVITY_ID CallerActId = Nav_Get_Top();

    if (MMI_MODEM_PIN_DISABLED == PinReqType)
    {
        return;
    }

    if (SETTING_PIN_REQUEST_POWERON == g_SettingSecurityPinReqStatus[SimId])
    {
        // do nothing, wait for framework's PIN check request
    }
    else
    {
        // if being in pin/puk operating, ignore RIL's notification to avoid unexpected UI display actions
        if (  (SETTING_SECURITY_ACTION_PIN_CODE_REQUEST ==
               g_SettingSecuritySettingMng.OperatingAction)
           ||
              (SETTING_SECURITY_ACTION_CHG_ACC_CODE == g_SettingSecuritySettingMng.OperatingAction)
           ||
              (SETTING_SECURITY_ACTION_EXT_PIN_CHK_NO_CNF ==
               g_SettingSecuritySettingMng.OperatingAction)
           ||
              (SETTING_SECURITY_ACTION_EXT_PIN_CHK_WITH_CNF ==
               g_SettingSecuritySettingMng.OperatingAction))
        {
            return;
        }

        Setting_Set_Operating_Action(SETTING_SECURITY_ACTION_EXT_PIN_CHK_NO_CNF);

        if (MMI_MODEM_SIM_1 == SimId)
        {
            // get sim status
            Setting_Set_Operating_Sim_Id(MMI_MODEM_SIM_1);

            if (MMI_MODEM_PIN1_REQUIRED == PinReqType)
            {
                Display_Setting_Enter_Security_Code(CallerActId, PHONE_TEXT_ID_ENTER_SIM1_PIN,CallerActId, TRUE);
            }
            else if (MMI_MODEM_PIN2_REQUIRED == PinReqType)
            {
                Display_Setting_Enter_Security_Code(CallerActId, PHONE_TEXT_ID_ENTER_SIM1_PIN2,CallerActId, TRUE);
            }
            else if (MMI_MODEM_PIN1_BLOCKED_PUK1_REQUIRED == PinReqType)
            {
                Display_Setting_Enter_Security_Code(CallerActId, PHONE_TEXT_ID_ENTER_SIM1_PUK,CallerActId, TRUE);
            }
            else if (MMI_MODEM_PIN2_BLOCKED_PUK2_REQUIRED == PinReqType)
            {
                Display_Setting_Enter_Security_Code(CallerActId, PHONE_TEXT_ID_ENTER_SIM1_PUK2,CallerActId, TRUE);
            }
            else if (MMI_MODEM_PUK1_BLOCKED == PinReqType)
            {
                Display_Setting_Security_Puk_Blocked(CallerActId, PHONE_TEXT_ID_SIM1PUK_BLOCKED,CallerActId);
            }
            else if (MMI_MODEM_PUK2_BLOCKED == PinReqType)
            {
                Display_Setting_Security_Puk_Blocked(CallerActId, PHONE_TEXT_ID_SIM1PUK2_BLOCKED,CallerActId);
            }
        }
        else
        {
            // get sim status
            Setting_Set_Operating_Sim_Id(MMI_MODEM_SIM_2);

            if (MMI_MODEM_PIN1_REQUIRED == PinReqType)
            {
                Display_Setting_Enter_Security_Code(CallerActId, PHONE_TEXT_ID_ENTER_SIM2_PIN,CallerActId, TRUE);
            }
            else if (MMI_MODEM_PIN2_REQUIRED == PinReqType)
            {
                Display_Setting_Enter_Security_Code(CallerActId, PHONE_TEXT_ID_ENTER_SIM2_PIN2,CallerActId, TRUE);
            }
            else if (MMI_MODEM_PIN1_BLOCKED_PUK1_REQUIRED == PinReqType)
            {
                Display_Setting_Enter_Security_Code(CallerActId, PHONE_TEXT_ID_ENTER_SIM2_PUK,CallerActId, TRUE);
            }
            else if (MMI_MODEM_PIN2_BLOCKED_PUK2_REQUIRED == PinReqType)
            {
                Display_Setting_Enter_Security_Code(CallerActId, PHONE_TEXT_ID_ENTER_SIM2_PUK2,CallerActId, TRUE);
            }
            else if (MMI_MODEM_PUK1_BLOCKED == PinReqType)
            {
                Display_Setting_Security_Puk_Blocked(CallerActId, PHONE_TEXT_ID_SIM2PUK_BLOCKED,CallerActId);
            }
            else if (MMI_MODEM_PUK2_BLOCKED == PinReqType)
            {
                Display_Setting_Security_Puk_Blocked(CallerActId, PHONE_TEXT_ID_SIM2PUK2_BLOCKED,CallerActId);
            }
        }
    }
} /* MMI_Modem_Pin_Status_Change_Ind */
